import requests
import pandas as pd
from lxml import html
url = 'https://zeon18.ru/page/search/?name=%D0%A2%D0%B5%D1%80%D0%BC%D0%BE%D0%BF%D0%B0%D1%81%D1%82%D0%B0'
tree = html.fromstring(requests.get(url).text)
def get_elements_by_xpath(xpath):
return [
html.tostring(element, method='text', encoding='unicode', with_tail=False)
for element in tree.xpath(xpath)
]
titles = get_elements_by_xpath('.//a[@class="catalog-item-title"]')
prices = get_elements_by_xpath('.//div[@class="catalog-item-price-main"]/span[@class="value"]')
pd.DataFrame(zip(titles, prices), columns=['title', 'price']).to_csv('catalog.csv', index=False)
items = ['abc', 'apple', 'pen', 'abc', 'pen', 'pc']
cache = {}
[cache.setdefault(item, len(cache)) for item in items]
from functools import lru_cache
from itertools import count
@lru_cache(maxsize=None)
def enumerate_as_seen(_, counter=count()):
return next(counter)
list(map(enumerate_as_seen, items))
a = [1, 2, 2, 3, 4, 3]
n = 2
list(zip(*[iter(a)]*n))
import numpy as np
np.array(a).reshape(-1, n)
import numpy as np
from itertools import count
def print_max_element(sequence, counter=count(0)):
print(f'Максимальный элемент в {next(counter)}-м столбце: {sequence.max()}')
np.apply_along_axis(print_max_element, 0, arr)
import numpy as np
a = [0, 1, 1, 2, 1, 3, 4, 4, 5, 4]
N = len(a)
a = np.array(a)
for n in range(3, N):
if N % n == 0:
b = a.reshape(-1, n)
b = np.diff(b, axis=1)
if np.all(b == b[0]):
print(n)
from operator import sub
a = [0, 1, 1, 2, 1, 3, 4, 4, 5, 4]
N = len(a)
for n in range(3, N):
if N % n != 0:
continue
matrix = list(zip(*[iter(a)]*n))
for i, row in enumerate(matrix):
matrix[i] = map(sub, row[1:], row[:-1])
transposed = zip(matrix)
row_to_set = map(set, transposed)
set_to_len = map(len, row_to_set)
if len(set(set_to_len)) == 1:
print(n)
arr[ arr < 17 ].tolist()
from itertools import groupby
def rle(text):
return [(key, len(tuple(group))) for key, group in groupby(text)]
print(*map(str, sorted(eval('[{}+{},{}+{}]'.format(*input())), reverse=True)), sep='')