Iterate over dictionary. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Iterate over dictionary.

data = [{'id': 1, 'name': 'aaaa'}, {'id': 2, 'name': 'bbbb'}, {'id': 3, 'name': 'cccc'}, {'id': 4, 'name': 'dddd'}, {'id': 5, 'name': 'eeee'}, {'id': 6, 'name': 'ffff'}] for d in data: for key in d: print (d['id'], d['name']) This prints all the item in the list containing dictionary but I want to print from id = 3 to id = 6.

12th May 2017, 7:37 PM
buggythegret
buggythegret - avatar
2 Answers
+ 7
You should change the first line to: for d in data[2:]:
12th May 2017, 7:40 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 1
Thanks Kuba. Always been a great help.
13th May 2017, 4:28 AM
buggythegret
buggythegret - avatar