Python Forum
Access list items in Python - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Access list items in Python (/thread-23457.html)



Access list items in Python - kamaleon - Dec-31-2019

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


RE: Access list items in Python - buran - Dec-31-2019

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.


RE: Access list items in Python - kamaleon - Dec-31-2019

I think I got it...

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