Python Forum

Full Version: Access list items in Python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

How can I access the values of A1, A2 and A3?

Is this a dictionary inside of a list?

>>> type(data)
<class 'list'>
>>> pprint(data)
[{'A1': 'BCN',
  'A2': 'To Offer jobs',
  'A3': 'yes',
  'Date Added': 'Dec 31, 2019',
  'Facebook User Name': 'Julian Pedersen',
  'First Name': 'Julian',
  'Group Name': 'Barcelona Events',
  'Joined': 'Jun 9, 2008',
  'Last Name': 'Pedersen',
  'User ID': 107345707},
 {'A1': 'barcelona',
  'A2': 'To meet people',
  'A3': 'no',
  'Date Added': 'Dec 31, 2019',
  'Facebook User Name': 'Tania Timush',
  'First Name': 'Tania',
  'Group Name': 'Barcelona Events',
  'Joined': 'Nov 27, 2017',
  'Last Name': 'Timush',
  'User ID': 100023456973042}]
Thanks
sorry, but you ask virtually the same question without trying to understand the solution offered and implement it yourself for this use case.
data is list of dicts. iterate over the elements in the list, then for each element (a dict) access the values you want.
I think I got it...

for words in data:
    print(words['A1'])
    print(words['A2'])
    print(words['A3'])