How do I print it out under certain conditions at a place on the list in Python Dictionary?

Asked 2 years ago, Updated 2 years ago, 15 views

Hello, I am writing because I have a question.

In a situation where a list of items is made in a dictionary like this

What should I do if I only try to print out people who are over a certain age?

For now, for I test1.values(): I thought about it.

After that, I can't print out the age of 25 or older on the if conditions.

test1= { list1' : [ {'name' : TVXQ', 'age' : 24}, {'name' : Yoo Jae-seok, 'age' : 34}, {'name' : 'IU', 'age' : 37}, ], list2 : [ {'name' : 'Kim Jinwoo', 'age' : 24}, {'name' : spring water', 'age' : 20}, {'name' : 'Jingu', 'age' : 25},

python

2022-09-20 16:31

1 Answers

for i in test1.values():
    for ii in i:
        if ii['age'] > 24:
            print(ii)


2022-09-20 16:31

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.