0

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'}]
1
  • This is a very basic question. You should have searched first. Commented Feb 6, 2014 at 3:34

2 Answers 2

1
  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
Sign up to request clarification or add additional context in comments.

Comments

0

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']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.