Python Forum
Getting a certain value from inside brackets.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting a certain value from inside brackets.
#4
Please, don't start new threads unnecessarily. Why do you say you got no helping answer?
@DeaD_EyE answer is waht you want. What is that you don't like about it.

You have list of dicts. You access elements in the list by index.

data = [{u'address': {u'altitude': None,
               u'area': u'',
               u'buildingNumber': None,
               u'country': None,
               u'latitude': None,
               u'longitude': None,
               u'street': u'',
               u'zip': u''},
  u'id': 123456,
  u'levelOfAccess': None,
  u'name': u'Schuppen',
  u'siteKey': u'YBCL-HXXX'}]

spam = data[0][u'siteKey'] # access element at index 0 and get value for key
print(spam)
if you have more than one item in the list, you may have to iterate over items in the list.

for item in data:
    spam = item[u'siteKey']
    print(spam)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: Getting a certain value from inside brackets. - by buran - Mar-01-2021, 03:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] [BeautifulSoup] Why does it turn inserted string's brackets into </>? Winfried 0 1,561 Sep-03-2022, 11:21 PM
Last Post: Winfried
  Reading list items without brackets and quotes jesse68 6 4,710 Jan-14-2022, 07:07 PM
Last Post: jesse68
  Data pulled from SQL comes in brackets nickzsche 3 2,722 Jan-04-2022, 03:39 PM
Last Post: ibreeden
  For Loop and Use of Brackets to Modify Dictionary in Tic-Tac-Toe Game new_coder_231013 7 2,337 Dec-28-2021, 11:32 AM
Last Post: new_coder_231013
  Removing internal brackets from a string Astrikor 4 2,726 Jun-04-2020, 07:54 PM
Last Post: Astrikor
  Taking brackets out of list in print statement pythonprogrammer 3 2,434 Apr-13-2020, 12:25 PM
Last Post: perfringo
  printing a list contents without brackets in a print statement paracelx 1 2,160 Feb-15-2020, 02:15 AM
Last Post: Larz60+
  Dictionnary brackets issue Reldaing 1 1,869 Nov-10-2019, 11:54 PM
Last Post: ichabod801
  how to remove brackets within a list A3G 17 18,395 Oct-16-2016, 02:34 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020