This week's book giveaways are in the Jython/Python and Object-Oriented programming forums.
We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Getting none for the value in dictionary even though it is defined in dictionary

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

As per my understanding if we have not defined the value in dictionary then we will get the None. But am getting none even though if the value is defined. Could anyone explain to me the below scenario?



And the out put is:


Enter the phone number12343
['1', '2', '3', '4', '3']
Three
None
None
None
None
None



And I will get it worked when I put the keys of dictionaries inside the quotes as below:


So, is it mandatory to use quotes for keys?
 
Marshal
Posts: 67343
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your first example the keys are numbers, not strings. In the second case they are strings. The second case works because you are using the strings from phone_num as the indexes, not numbers.
 
Sarah Jay
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:In your first example the keys are numbers, not strings. In the second case they are strings. The second case works because you are using the strings from phone_num as the indexes, not numbers.



Thanks, Bear...

You mean to say I should not cast it to list then it will work fine...I have tried that too...It dint worked for me...Could you please explain to me little in a little bit clearer way...
 
There were millions of the little blood suckers. But thanks to this tiny ad, I wasn't bitten once.
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!