Reputation: 650
I have a list as below: How do I do index in python. I want to fetch a value for "OS"? Please let me know.
[{'UserName': 'd699a1f25d9a3', 'BrowserVersion': None, 'PasswordMinLength': 0, 'SystemAutoLock': 0, 'OS': 'Windows 7 6.1 Build 7601 : Service Pack 1 64bit'}]
Upvotes: 0
Views: 86
Reputation: 36
mylist = [{'UserName': 'd699a1f25d9a3', 'BrowserVersion': None, 'PasswordMinLength': 0, 'SystemAutoLock': 0, 'OS': 'Windows 7 6.1 Build 7601 : Service Pack 1 64bit'}]
OS = mylist[0]['OS']
print OS
Upvotes: 1
Reputation: 34146
Let's say your list is stored in variable my_list
:
mylist = [{'UserName': 'd699a1f25d9a3', 'BrowserVersion': None, 'PasswordMinLength': 0, 'SystemAutoLock': 0, 'OS': 'Windows 7 6.1 Build 7601 : Service Pack 1 64bit'}]
Since the dictionary is the first element of the list, you can access to it using indexing. Remember that indexes start with 0
:
my_list[0] # first element
Then you can access to a key in the dictionarie by its corresponding value: my_dict[key]
. In your case:
my_list[0]['OS']
Upvotes: 0