By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,654 Members | 1,842 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,654 IT Pros & Developers. It's quick & easy.

How to access second and another value of a key?

P: 4
Expand|Select|Wrap|Line Numbers
  1. dicc ={ "key" : ["value1", "value2"], ...}
  2.  
How can I access the second value?

I can do :
Expand|Select|Wrap|Line Numbers
  1. for i in dicc:
  2.     print(dicc[i])
  3.  
  4. or
  5.  
  6. for i in dicc:
  7.     print(dicc.get(i))
  8.  
but it will print me both values and i need to access only first one or second one,third etc...cant use slices cooz of the error.
Aug 14 '15 #1

✓ answered by Dietrich41

Expand|Select|Wrap|Line Numbers
  1. dicc = { "key" : ["value1", "value2"]}
  2.  
  3. for k, v in dicc.items():
  4.     print(v[1])
  5.  

Share this Question
Share on Google+
1 Reply


P: 1
Expand|Select|Wrap|Line Numbers
  1. dicc = { "key" : ["value1", "value2"]}
  2.  
  3. for k, v in dicc.items():
  4.     print(v[1])
  5.  
Aug 14 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.