469,645 Members | 1,424 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,645 developers. It's quick & easy.

dictionary with lists as values

rhitam30111985
112 100+
ok.. here is the problem: consider the following dictionary..
it has a country name as a key and list of offices as values:

Expand|Select|Wrap|Line Numbers
  1. offices={'USA':['google','microsoft','apple','infosys'],
  2.        'ireland':['apple','accenture','dupont'],
  3.        'india':['infosys','accenture','TCS','dupont']
  4. }
  5.  
now supposed i enter the name of an office as an input form the user.. for example infosys... then i should get india and USA as my output...
how do i go about it?

thanks in advance
Aug 22 '07 #1
4 932
bartonc
6,596 Expert 4TB
ok.. here is the problem: consider the following dictionary..
it has a country name as a key and list of offices as values:

Expand|Select|Wrap|Line Numbers
  1. offices={'USA':['google','microsoft','apple','infosys'],
  2.        'ireland':['apple','accenture','dupont'],
  3.        'india':['infosys','accenture','TCS','dupont']
  4. }
  5.  
now supposed i enter the name of an office as an input form the user.. for example infosys... then i should get india and USA as my output...
how do i go about it?

thanks in advance
Expand|Select|Wrap|Line Numbers
  1. >>> for country, officeList in offices.items():
  2. ...     if "infosys" in officeList:
  3. ...         print country
  4. ...         
  5. india
  6. USA
  7. >>> 
Aug 22 '07 #2
rhitam30111985
112 100+
Expand|Select|Wrap|Line Numbers
  1. >>> for country, officeList in offices.items():
  2. ...     if "infosys" in officeList:
  3. ...         print country
  4. ...         
  5. india
  6. USA
  7. >>> 
oh... looks like i gotta go over the manual more thoroughy... thanks a lot barton
Aug 22 '07 #3
bartonc
6,596 Expert 4TB
oh... looks like i gotta go over the manual more thoroughy... thanks a lot barton
Any time, really. Have fun!

Note that the order of the output is indeterminate.
Aug 22 '07 #4
rhitam30111985
112 100+
Any time, really. Have fun!

Note that the order of the output is indeterminate.
hmm.. order is indeterminate.. didnt notice that.. anyway.. that is not a problem...
Aug 22 '07 #5

Post your reply

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

Similar topics

2 posts views Thread by neutrinman | last post: by
125 posts views Thread by Raymond Hettinger | last post: by
90 posts views Thread by Christoph Zwerschke | last post: by
7 posts views Thread by David Bear | last post: by
10 posts views Thread by Ben | last post: by
4 posts views Thread by =?utf-8?B?TWFjaWVqIEJsaXppxYRza2k=?= | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.