Похожие чаты

So basically, i would like to get the value of

a dictionary. the value of a dictionary is a nested list. when i index v[0], i manage to get the first element in the list. when i index v[1] in order for me to get the second element in a list, index is out of range. how do i get this solve pls?

13 ответов

5 просмотров

Use for

CH- Автор вопроса
Gian
Use for

You mean using for loop to iterate it? I can’t get each of the element in the list by indexing it?

CH
You mean using for loop to iterate it? I can’t get...

You can, but you need all of them to have the same size. using a for you don't assume anything about the list size.

CH- Автор вопроса
Gian
You can, but you need all of them to have the same...

Ah no wonder as one of the list just contain 1 element in it… Thank you so much!

Gian
Yes, precisely.

Can we use if and length? if len(v) >= 2: print(v[2]) else: print(v[1])

ANDRIO
Can we use if and length? if len(v) >= 2: pri...

why? what if the list is empty? if it has 3 items, 4?

Gian
why? what if the list is empty? if it has 3 items,...

What if we first check if the length of list is greater than 1 then run a for loop to print the list

ANDRIO
What if we first check if the length of list is gr...

You can check the length of the list, but you can also use list comprehension for printing things too

Gian
You can check the length of the list, but you can ...

Yes but that syntax looks difficult to read for me

ANDRIO
Yes but that syntax looks difficult to read for me

Depending on what you want/need, it's the way to write consistent code. But I agree the syntax is weird.

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта