как найти нет. человека из определенной страны из кода ниже?

[
{'Year': 1901,
  'Category': 'Chemistry',
  'Prize': 'The Nobel Prize in Chemistry 1901',
  'Motivation': '"in recognition of the extraordinary services he has rendered by the discovery of the laws of chemical dynamics and osmotic pressure in solutions"',
  'Prize Share': '1/1',
  'Laureate ID': 160,
  'Laureate Type': 'Individual',
  'Full Name': "Jacobus Henricus van 't Hoff",
  'Birth Date': '1852-08-30',
  'Birth City': 'Rotterdam',
  'Birth Country': 'Netherlands',
  'Sex': 'Male',
  'Organization Name': 'Berlin University',
  'Organization City': 'Berlin',
  'Organization Country': 'Germany',
  'Death Date': '1911-03-01',
  'Death City': 'Berlin',
  'Death Country': 'Germany'},
 {'Year': 1901,
  'Category': 'Literature',
  'Prize': 'The Nobel Prize in Literature 1901',
  'Motivation': '"in special recognition of his poetic composition, which gives evidence of lofty idealism, artistic perfection and a rare combination of the qualities of both heart and intellect"',
  'Prize Share': '1/1',
  'Laureate ID': 569,
  'Laureate Type': 'Individual',
  'Full Name': 'Sully Prudhomme',
  'Birth Date': '1839-03-16',
  'Birth City': 'Paris',
  'Birth Country': 'France',
  'Sex': 'Male',
  'Organization Name': '',
  'Organization City': '',
  'Organization Country': '',
  'Death Date': '1907-09-07',
  'Death City': 'Châtenay',
  'Death Country': 'France'}
]

1 ответ

Если вы хотите узнать, сколько человек принадлежит к той же стране рождения только из заданного списка dict, вы можете использовать следующий код:

from collections import Counter

li = [each['Birth City'] for each in val if each['Birth City']]
print(dict(Counter(li)))

ВЫХОД

{'Rotterdam': 1, 'Paris': 1}
Другие вопросы по тегам