• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Screaming fools! It's nothing more than a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic