Skip to content

Instantly share code, notes, and snippets.

@koorgoo
Created March 18, 2020 21:28
Show Gist options
  • Save koorgoo/910bc25043d2416aad1cb1658317261f to your computer and use it in GitHub Desktop.
Save koorgoo/910bc25043d2416aad1cb1658317261f to your computer and use it in GitHub Desktop.
Olya.3
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