-2
In [4]: {'a': "hello"}['a']
Out[4]: 'hello'

I want the output to instead be:

Out[4]: hello

What's the most elegant way to achieve this?

I am also using repr().rjust() later on to print a list of dictionaries into a neatly formatted table, and I notice the repr function also adds quotes which is annoying:

def print_dictionary(d): print repr(d['a']).rjust(10)
print_dictionary({'a':'hello'})

yields:

   'hello'

when I want:

     hello
cas5nq
  • 413
  • 5
  • 11

1 Answers1

0

Just drop the repr:

def print_dictionary(d): print (d['a']).rjust(10)
Mureinik
  • 297,002
  • 52
  • 306
  • 350
  • Thanks! I don't know why I was using repr. I just copied it from an example that had it but now I realize it is unnecessary. – cas5nq Oct 18 '14 at 23:05