@fotosyfondos · Post #9728 · 23.11.2018 г., 16:39
📸🖼📸🖼📸🖼📸🖼📸🖼📸🖼 ➡️ Fantasmas #Fantasmas#Terror#Luigi#FondosDePantalla @fotosyfondos 📸🖼📸🖼📸🖼📸🖼📸🖼📸🖼
TGINSIGHT SIMILAR POSTS
Изворен канал @pythonotes · Post #65 · 8 апр.
Небольшой трик с регулярными выражениями который редко вижу в чужом коде. Допустим, вам нужно распарсить простой текст и вытащить оттуда пары имя+телефон. Вернуть всё это надо в виде списка словарей. Возьмем очень простой пример текста. >>> text = ''' >>> Alex:8999123456 >>> Mike:+799987654 >>> Oleg:+344456789 >>> ''' Соответственно, для выделения нужных элементов будем использовать группы. Получится такой паттерн: (\w+):([\d+]+) Как мы будем формировать словарь из найденных групп? >>> import re >>> results = [] >>> for match in re.finditer(r"(\w+):([\d+]+)", text): >>> results.append({ >>> "name": match.group(1), >>> "phone": match.group(2) >>> }) >>> print(results) [{'name': 'Alex', 'phone': '8999123456'}, ...] Можно немного сократить запись используя zip >>> results = [] >>> for match in re.finditer(r"(\w+):([\d+]+)", text): >>> results.append(dict(zip(['name', 'phone'], match.groups()))) Но есть способ лучше! Это именованные группы в regex. Можно в паттерне указать имя группы и результат сразу забрать в виде словаря. >>> for match in re.finditer(r"(?P<name>\w+):(?P<phone>[\d+]+)", text): >>> results.append(match.groupdict()) То есть всё что я сделал, это добавил в начале группы (внутри сбокочек) такую запись: (?P<group-name>...) Теперь найденная группа имеет имя и можно обратиться к ней как к элементу списка >>> name = match['name'] Либо забрать сразу весь словарь методом groupdict() >>> match.groupdict() #tricks#regex
Пребарај: #luigi
@fotosyfondos · Post #9728 · 23.11.2018 г., 16:39
📸🖼📸🖼📸🖼📸🖼📸🖼📸🖼 ➡️ Fantasmas #Fantasmas#Terror#Luigi#FondosDePantalla @fotosyfondos 📸🖼📸🖼📸🖼📸🖼📸🖼📸🖼
@djangoproject · Post #275 · 18.03.2017 г., 01:51
https://github.com/spotify/luigi Writing batch jobs is generally only one part of processing heaps of data; you also have to string all the jobs together into something resembling a #workflow or a #pipeline. #Luigi, created by Spotify and named for the other plucky plumber made famous by Nintendo, was built to "address all the plumbing typically associated with long-running batch processes." With Luigi, a developer can take several different unrelated data processing tasks — "a Hive query, a Hadoop job in Java, a Spark job in Scala, dumping a table from a database" — and create a workflow that runs them, end to end. The entire description of a job and its dependencies are created as Python modules, not as XML config files or another data format, so it can be integrated into other Python-centric projects. #Machine_learning