Найти - Пользователи
Полная версия: Сортировка url ссылок
Начало » Центр помощи » Сортировка url ссылок
1
iNdexoiD
Подскажите плиз как можно отсортировать.Чтоб у меня построчно список был url
Сейчас у меня такого вида:
http://s.ggwp.be/w2tr;http://site
http://s.ggwp.be/w2ук;http://site
http://eu20.es/atr;http://site

Тоесть мне нужно всё что идёт в первой колонке оставить,нужно убрать ;http://site

Чтоб было так:
http://s.ggwp.be/w2tr
http://s.ggwp.be/w2ук
http://eu20.es/atr
botinag
>>> urls = ['http://s.ggwp.be/w2tr;http://site', 'http://s.ggwp.be/w2ук;http://site', 'http://eu20.es/atr;http://site']
>>> [url.replace(';http://site', '') for url in urls]
['http://s.ggwp.be/w2tr', 'http://s.ggwp.be/w2\xe3\xaa', 'http://eu20.es/atr']
iNdexoiD
sed ‘s/;.*$//’
terabayt
urls = ['http://s.ggwp.be/w2tr;http://site', 'http://s.ggwp.be/w2ук;http://site', 'http://eu20.es/atr;http://site']
map(lambda x: x.split(';', 1)[0], urls)
iNdexoiD
у меня в файле список большой
pyuser
with open(source_file_name, "rt", encoding="utf-8") as fin,
        open(output_file_name, "wt", encoding="utf-8") as fout:
    for line in fin:
        print(line.split(";")[0], file=fout)
либо:
def get_urls(fname):
    with open(fname, "rt", encoding="utf-8") as fin:
        yield from map(lambda s: s.split(";")[0], fin)
for url in get_urls(source_file_name):
    ...
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB