In [ ]:
features_tuple = ('Ivan Ivanovich', 'Medium', 500000, 12, True)
print (type(features_tuple))
In [ ]:
#Функция tuple() берет в качестве аргумента строку или список и превращает его в кортеж:
tuple('abc')
In [ ]:
features_tuple[2:5]
In [ ]:
features_tuple.append('one more element')
In [ ]:
help(tuple)
In [ ]:
Äàí ñïèñîê êîðòåæåé grades=[("Ann 4),("Bob 2),("Elizabeth 3),("Dan 5)]. Âûâåñòè íà ýêðàí ïîñëå-
äîâàòåëüíîñòü ñîîáùåíèé âèäà
Hello, Ann! Your grade is 4.
In [ ]:
names = {'Ivan', 'Petr', 'Konstantin'}
In [ ]:
print (type(names))
In [ ]:
'Ivan' in names
In [ ]:
help(set)
In [ ]:
'Mikhail' in names
In [ ]:
names.add('Mikhail')
print (names)
In [ ]:
names.add('Mikhail')
names
In [ ]:
names.remove('Mikhail')
names
In [ ]:
names.add(['Vladimir', 'Vladimirovich'])
In [ ]:
names.add(('Vladimir', 'Vladimirovich'))
names
In [ ]:
a = range(10000000)
b = range(10000000)
b = set(b)
In [ ]:
a[:5]
In [ ]:
a[-5:]
In [ ]:
%%time
i = 0
for num in a:
i +=1
print ('Found ', i, 'times')
In [ ]:
%%time
0 in b
Задача. Дан список чисел. Определите, сколько в нем встречается различных чисел.
Примечание. Эту задачу на Питоне можно решить в одну строчку.
In [ ]:
words_frequencies = dict()
words_frequencies['I'] = 1
words_frequencies['am'] = 1
words_frequencies['I'] += 1
words_frequencies
In [ ]:
help(dict)
In [ ]:
words_frequencies['I']
In [ ]:
words_frequencies = {'I': 2, 'am': 1}
words_frequencies
In [ ]:
yet_another_dict = {'abc': 3.4, 5: 7.8, u'123': None}
yet_another_dict
In [ ]:
yet_another_dict[(1,2,5)] = [4, 5, 7]
yet_another_dict
In [ ]:
yet_another_dict[[1,2,7]] = [4, 5]
In [ ]:
str = 'time to study and for free time.'
str.split(' ')
In [ ]:
str.split()
In [ ]:
str1 = str.split()[6]
In [ ]:
str1.endswith('.')
In [ ]:
str1.replace('.','')
In [ ]:
dict = dict()
In [ ]:
dict['time'] = 1
dict['time']
In [ ]:
'time' in dict.keys()
In [ ]: