forked from ItPeoplePython2018/lesson-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython_log.txt
103 lines (100 loc) · 2.34 KB
/
python_log.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
~/Src/python-lessons/lesson-2$ python3
Python 3.6.4 (default, Dec 21 2017, 20:33:21)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> math
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'math' is not defined
>>> import math
>>> math
<module 'math' from '/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload/math.cpython-36m-darwin.so'>
>>> math.pow(5, 2)
25.0
>>> math.pow(5, 3)
125.0
>>> math.pow(5, 4)
625.0
>>> math.sqrt(math.pow(5, 4))
25.0
>>> math.sqrt(25)
5.0
>>> def func():
... pass
...
>>> print(func())
None
>>> def func():
... return 123
...
>>> print(func())
123
>>> var = func()
>>> import collections
>>> d = {}
>>> l = ['привет', 'пока', 'утро', 'вечер']
>>> {'п': ['привет', 'пока'], 'у': ['утро'], 'в': ['вечер']}
{'п': ['привет', 'пока'], 'у': ['утро'], 'в': ['вечер']}
>>> for i in l:
...
KeyboardInterrupt
>>> a = 'привет'
>>> a[0]
'п'
>>> l[0]
'привет'
>>> l[0][0]
'п'
>>> d
{}
>>>
>>> for i in l:
...
KeyboardInterrupt
>>> for word in l:
...
File "<stdin>", line 2
^
IndentationError: expected an indented block
>>> dd = {'a': 1}
>>> dd['a']
1
>>> aa = 'a'
>>> dd[aa]
1
>>> dd['hello'] = 12345
>>> dd
{'a': 1, 'hello': 12345}
>>> for word in l:
... bck:
...
>>> for word in l:
... d[word[0]] = [word]
...
>>> d
{'п': ['пока'], 'у': ['утро'], 'в': ['вечер']}
>>> l
['привет', 'пока', 'утро', 'вечер']
>>> d = {}
>>> for word in l:
... first_char = word[0]
... if first_char in d:
... d[first_char].append(word)
... else:
... d[first_char] = [word]
...
>>> d
{'п': ['привет', 'пока'], 'у': ['утро'], 'в': ['вечер']}
>>> collection.defaultdict
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'collection' is not defined
>>> collections.defaultdict
<class 'collections.defaultdict'>
>>> d = collections.defaultdict(list)
>>> for word in l:
... first_char = word[0]
... d[first_char].append(word)
...
>>> d
defaultdict(<class 'list'>, {'п': ['привет', 'пока'], 'у': ['утро'], 'в': ['вечер']})