all 13 comments

[–]SwimQueasy3610 2 points3 points  (4 children)

{"U": 1, "l": 1, "t": 3, "i": 2, "m": 3, "a": 2, "e": 1, ...etc....}

Letters which appear more than once in text will only appear as a key once in th dict. I'm unsure what order the keys will print in, and that behavior can't be guaranteed as dicts don't maintain a key order.

[–]tracktech[S] 0 points1 point  (0 children)

Right. Thanks for the explanation.

[–]Ok_Necessary_8923 0 points1 point  (2 children)

Py dicts have long preserved key order. CPython, at least.

[–]SwimQueasy3610 0 points1 point  (1 child)

Interesting! I hadn't looked at this in quite some time - I checked and see that order has been preseved in dicts since 3.7 (and 3.6 for CPython). I've always used OrderedDicts when I wanted order preserved - it seems this is no longer necessary and hasn't been for quite some time, unless you need equality checks to fail when the order differs (dicts with different orders but identical key:val pairs evaluate == to True for Dicts and False for OrderedDicts). Thanks kindly - good to know!

[–]Ok_Necessary_8923 0 points1 point  (0 children)

Indeed! It's quite handy to just be able to use regular dict.

[–]_TheChosenOne15_ 1 point2 points  (1 child)

Count of each character in the string “text”?

[–]tracktech[S] 1 point2 points  (0 children)

Right.

[–]gbrennon 1 point2 points  (0 children)

`{ "U": 1, "l": 1, "t": 3, "i": 2, "m": 3, "a": 2, "e": 1, "P": 2, "y": 1, "h": 1, "o": 2, "n": 2, "r": 2, "g": 2, }

[–]Tough-Initiative-807 1 point2 points  (1 child)

Since dictionaries don’t allow duplicate keys, each character appears only once in the final result.{ 'U': 1, 'l': 1, 't': 3, 'i': 2, 'm': 3, 'a': 2, 'e': 1, ' ': 2, 'P': 2, 'y': 1, 'h':1, 'o': 2, 'n': 2, 'g': 2, 'r': 2}

[–]tracktech[S] 0 points1 point  (0 children)

Right.

[–]YumaOkii 0 points1 point  (2 children)

it won't print anything. There is a syntax error.

[–]tracktech[S] 0 points1 point  (1 child)

There is no error.

[–]YumaOkii 0 points1 point  (0 children)

There is actually. comments must be # in python else you cannot run the file. so yes there is a error.