Help with 19/19


#1

While addind new item to my dictonary it gets saved with u’ before it, as in output.
How to avoid this?


#2

There are also colons, spaces, commas, apostrophes and curly braces, why is it the u’s that need to go but none of the rest?


#3

whoa, I didnt expect reply so soon, thanks :smiley:
Ok, so I understand that colons and commas are there while just using print and i dont mind them (but will apriciate if you told me how to print it nicely), what i dont understand where did this u’ came from and how to add item to dictonary without it

Thanks


#4

Create the string you want to output, and then do so

Having python convert a dict to string is rarely something you’d do when showing something to and end user. You’d write code to format it the way you want.

That u doesn’t deserve any more attention than all those other symbols, so “how to avoid it” is, from my perspective, the wrong question


#5

For example, printing nicely might mean getting all the keys, sorting alphabetically, then for each key look up the value, print them both, perhaps you’d put something between them:

for key in sorted(merchandise):
    print '{}: {}'.format(key, merchandise[key])

#6

Yea, I understood what you meant so I used for loop too (without sorted and .format, which I’ll try now) but thanks anyway! :smiley:


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.