(dx, dy) = (-dy, dx)
import csv
from geopy.geocoders import AlgoliaPlaces as Geo
cities = ["Токио", "Лондон", "Берлин", "Череповец"]
geo = Geo()
data = []
for i in cities:
n = geo.geocode(i)
data.append([i, n.latitude, n.longitude])
with open('data.csv', 'w', newline='') as f:
w = csv.writer(f)
w.writerow(['city', 'lat', 'lon'])
w.writerows(data)
def sumelem(seq, step):
for i, elem in enumerate(seq,1):
if i%step:
yield elem
else:
yield elem
yield sum(seq[i-step:i])
print(*sumelem(a, 5))
a = [1, 2, 23, 4, 5, 6, 7, 40, 9, 10, 100, 12, 13, 14, 15, 700, 17, 18, 19, 20]
for index, group in reversed(list([(i, a[i:i+5]) for i in range(0, len(a), 5)])):
s = sum(group)
a.insert(index + 5, s)
print(f'{index} {group} => {s}')
# 15 [700, 17, 18, 19, 20] => 774
# 10 [100, 12, 13, 14, 15] => 154
# 5 [6, 7, 40, 9, 10] => 72
# 0 [1, 2, 23, 4, 5] => 35
# a
# [1, 2, 23, 4, 5, 35, 6, 7, 40, 9, 10, 72, 100, 12, 13, 14, 15, 154, 700, 17, 18, 19, 20, 774]
def generate(sequence, group_by=5, func=sum):
for group in zip(*[iter(sequence)]*group_by):
yield from group
yield func(group)
print(*generate(a))
with open('text.txt', 'r') as f:
import re
print(max([len(i[0]) for i in re.findall('((XYZ)+(X|XY)?)', f.read())]))
"последний фрагмент может быть неполным"
main('C:\\Directory\\Path\\test.txt', 'C:\\Directory2\\Path\\')
main('C:/Directory/Path/test.txt', 'C:/Directory2/Path/')
print("\u001b[30m")
print("\u001b[31m")
print("\u001b[32m")
print("\u001b[33m")
print("\u001b[34m")
print("\u001b[35m")
print("\u001b[36m")
print("\u001b[37m")