-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.

3
  • 5
    my suggestion would be to read Beginning Programming Python Commented Jul 17, 2017 at 8:07
  • Did you try to type in Google python dict get keys? Commented Jul 17, 2017 at 8:07
  • The official Tutorial in the Python Documentation should be a good starting point. This will help you create a valid data structure - your "dict" is not valid Python. Commented Jul 17, 2017 at 8:11

3 Answers 3

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'}

Sign up to request clarification or add additional context in comments.

Comments

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.

3 Comments

There's nothing strange about unicode.
@kabanus I'm not talking about u, I'm talking about text:u, which (at least in my Python 3) is invalid syntax.
Ahh, I see. I think it's an IDE thing, and he just pasted from my terminal.
-1

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.