#!/usr/bin/env python3
counts = dict()
with open('input.txt', 'rt') as fin:
for line in fin:
for word in line.split():
counts[word] = counts.get(word, 0) + 1
max = 0
max_word = set()
for word, cnt in counts.items():
if cnt > max:
max_word = {word}
max = cnt
if cnt == max:
max_word.add(word)
with open('output.txt', 'wt') as fout:
fout.write(min(max_word))
#!/usr/bin/env python3
def do(n):
tot.add(n)
for i in arr[n-1]:
if i not in tot:
do(i)
tot = set()
arr = []
for i in range(int(input())):
arr.append(list(map(int,input().split())))
do(1)
print(len(tot))
class figura():
def __init__(self, x, y, colour):
self.x = x
self.y = y
self.colour = colour
class pewka(figura):
def __init__(self, x, y, colour):
super().__init__(x, y, colour)
self.type = "pewka"
class ladja(figura):
def __init__(self, x, y, colour):
super().__init__(x, y, colour)
self.type = "ladja"
fig1 = pewka('a', 1, 'red')
fig2 = ladja('a', 1, 'red')
if any_fig.colour = 'red':
...
from random import random
wt = [60,30,10] # массив весов
cw = 0 # тут будем накапливать веса
rv = random() * sum(wt) # берем рандом от 0 до 1 и приводим к масштабу (сумма весов)
for j in range(len(wt)): # проходим по всем весам
cw += wt[j] # прибавляем к аккумулятору вес
if cw > rv: # проверяем не превысил ли накопленный вес случайное значение?
break # если превысил, значит в диапазон этого веса мы и попали.
print(j) # печатаем найденный индекс
from random import randint
def generate(dots):
a = set()
while len(a) < dots:
a.add((randint(0, dots), randint(1, dots)))
return list(a)
return [list(i) for i in list(a)]
import re
str = """какойтотекст
блаблабла
<root>
...
<child name=name id=id>
<child name=name1 id=id1>
...
</root>
какойтотекст"""
print(''.join(re.findall(r'(.*)<root>.*</root>(.*)', str, re.DOTALL)[0]))
import time
import random
guns = {'флобер': 8, 'наган': 7, 'кольт': 6}
while True:
while True:
gun = input('Добро пожаловать в русскую рулетку!\n'
'Флобер(8 патронов),Наган(7) либо Кольт(6)?\n'
'Выберите револьвер:')
if gun.lower() not in guns.keys():
print('Неверный револьвер')
else:
break
bullets = guns[gun]
while True:
choice = int(input('Введите количеством патронов в барабане'
' (от 1 до %d):'%bullets))
if choice == bullets:
print('Ну ты же знаешь что с полным барабаном у тебя нет шансов...')
elif choice <= 0 or choice >= bullets:
print('Некорректное количество патронов')
else:
break
print('Барабан вращается')
turn = random.randint(1, bullets)
time.sleep(turn)
if turn >= choice:
print('Ты выиграл')
else:
print('Ты проиграл!')