Created
March 18, 2020 21:28
-
-
Save koorgoo/910bc25043d2416aad1cb1658317261f to your computer and use it in GitHub Desktop.
Olya.3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dima@carbon:~$ python3 | |
Python 3.6.9 (default, Nov 7 2019, 10:44:02) | |
[GCC 8.3.0] on linux | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> d = dict() | |
>>> d[ | |
... 1] = 2 | |
>>> d | |
{1: 2} | |
>>> d[1] = 2 | |
>>> d | |
{1: 2} | |
>>> d[1] | |
2 | |
>>> d[1] += 1 | |
>>> d | |
{1: 3} | |
>>> d[1] = 1 | |
>>> if 1 in d: | |
... d[1] += 1 | |
... d | |
File "<stdin>", line 3 | |
d | |
^ | |
SyntaxError: invalid syntax | |
>>> if 1 in d: | |
... d[1] += 1 | |
... | |
>>> d | |
{1: 2} | |
>>> text = '' | |
>>> words = text.split() | |
>>> # text = f.read() | |
... | |
>>> counts = dict() | |
>>> for word in words: | |
... if word not in counts: | |
... count[word] = 0 | |
... if word not in counts: | |
KeyboardInterrupt | |
>>> for word in words: | |
... if word not in counts: | |
... counts[word] = 0 | |
... counts[word] += 1 | |
... | |
>>> for key, value in d.items(): | |
KeyboardInterrupt | |
>>> inverted = [] | |
>>> for key, value in d.items(): | |
... inverted.append((value, key)) | |
... | |
>>> inverted.sort() | |
>>> inverted.sort(reverse=True) | |
>>> | |
>>> abc = [] | |
>>> for value, key in inverted: | |
... abc.append(key) | |
... | |
>>> print(' '.join(abc)) | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
TypeError: sequence item 0: expected str instance, int found | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment