I have a dictionary of the form
Data = {'USA':[100,250],'Canada':[481,660],'China':[245,700],'Italy':[878,828],'Germany':[643,454]}
I can use list comprehension but is there a way to by using "only" for loop in Python, I can output the list of the first elements of each key in the dictionary?
For example, expected output is [100, 481, 660, 700, 828, 454].
And another separate question is how can I output only "the keys" associated with those first elements of those values if greater than 500 by using "for loop", and "if condition", only?
In this case, the output be a list as Country_list = ['Italy', 'Germany'].
Aucun commentaire:
Enregistrer un commentaire