How to print all 2 from this? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to print all 2 from this?

my_data = [{'list':[1,2,3,4,5]}, {'list1':[1,2,3,4,5,{'list2':[1,2,3,4,5]}]}, [[1,2,3,4,5,6]],1,2,3,4]

17th Dec 2021, 1:54 AM
Padma balaji
Padma balaji - avatar
1 Answer
0
There are six 2s to print. Start with the last (6th) one, which is at the end of my_data, as it would use plain and straightforward list indexing, and it requires the least amount of syntax. The rest are addressed by combinations of nested lists and dictionary keys. In order from least complicated to most complicated, try writing one print statement at a time to print each: 6th 5th 1st 2nd 4th 3rd [tricky: it's in the key name!]
17th Dec 2021, 3:06 AM
Brian
Brian - avatar