-4
[
{'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'}
]
khelwood
  • 55,782
  • 14
  • 81
  • 108
  • Just want to make clear that I'm new to coding....the above is a sample data set.Just want to know what should be the approach. for example : the above dataset type is list so should I convert it to dictionary etc.Please correct me if I'm wrong. – Vishnu Sreenivasan Nov 22 '19 at 07:27
  • Let's say the name of the list is `data`, then initialize a dict, `d = {}`. Then iterate over the list and add the the country names as key with vaue 0 to the dictionary if it does not already exists, otherwise add 1 to it. `d = {person['Birth Country'] : d.get('Birth Country',0) + 1 for person in data}` – Sayandip Dutta Nov 22 '19 at 07:37

1 Answers1

1

If you want to find, how many person belong to same birth country only from given list of dict, you can use the following code :

from collections import Counter

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

OUTPUT

{'Rotterdam': 1, 'Paris': 1}
Shivam Gupta
  • 201
  • 1
  • 5