472,106 Members | 1,296 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,106 software developers and data experts.

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 996
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 leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.