-4

How to access key 'Description' from dict below?

{text:u'Description': u'ABC',text:u'Balance': u'35,402,678.51',text:u'Credit': u'10,000.00'}

Tried using mydict.get('Description') & mydict['Description']. please provide your suggestions, i am new to python.

Mike Scotty
  • 10,530
  • 5
  • 38
  • 50
usr_11
  • 548
  • 10
  • 31
  • 5
    my suggestion would be to read [Beginning Programming Python](http://thepythonguru.com/) – zetavolt Jul 17 '17 at 08:07
  • Did you try to type in Google `python dict get keys`? – kabanus Jul 17 '17 at 08:07
  • The official [Tutorial in the Python Documentation](https://docs.python.org/3.6/tutorial/datastructures.html#dictionaries) should be a good starting point. This will help you create a valid data structure - your "dict" is not valid Python. – Christian König Jul 17 '17 at 08:11

3 Answers3

0

In your example, all your keys have a strange text: prefix, that result in an invalid dictionary (or rather in invalid syntax).

Otherwise your attempts are correct:

mydict = {u'Description': u'ABC',
u'Balance': u'35,402,678.51',
u'Credit': u'10,000.00'}

v = mydict.get('Description')

print(v) # ABC

By the way, if you get an error, you should add the complete traceback to your question, this will make it easier for us to help you.

Mike Scotty
  • 10,530
  • 5
  • 38
  • 50
0

“text:” is redundant, it can be left out.

dic = {u'Description': u'ABC', u'Balance': u'35,402,678.51', u'Credit': u'10,000.00'}

lejoy
  • 1
-1

Got the solution. error was due to "text" prefix. eliminated it using (myxlrdcell).value

usr_11
  • 548
  • 10
  • 31