TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

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

Резултати

Пронајдени 2 слични објави

Пребарај: #crank

当前筛选 #crank清除筛选
Libreware

@libreware · Post #1007 · 05.11.2021 г., 00:54

We just pushed the V1.2 of the Beechat Crank to our GitHub @beechatnetwork2 Beechat Crank is a human-powered, open-hardware, fully-waterproof, electricity generator. The project was born out of the need to power electronics in all off-grid scenarios. We needed a way to power our devices in all weather conditions, and making a human-powered generator meant that problem could be solved. When we looked for a solution, we didn't find what we were looking for, so we decided to make it, and make it open source! https://github.com/BeechatNetworkSystemsLtd/BeechatCrank/ Features High power (3A) USB-C IPX8 output 18650 3600 mAh battery (LG M36) Charging time of 4 hrs 24 min. to full charge with 10% efficiency loss at 4.5 Watts. Overcharge protection Parts Beechat Crank is composed of the main device, which we call the Heart. It contains the battery, the generator and all the electronics (the handle is detachable) The Pedal Case is an assembly which the Heart can be attached in. which dramatically speeds up the charging from 2.5 hours to 25-30 minutes. This is achieved with reduction gears to, with the same revolutions per minute, generate more electricity. Generator part We have chosen the 35L048B1B motor with a mass of 88 grams, giving us us 450 mA for each phase of the coil and works at 5V. The wire leads are connected via female Molex connectors to the charging PCB board. New modifications: * Added a Molex type connector to the PCB to connect the motor. * The Zener diodes were changed, by means of a rectifier bridge. * A new and improved Texas Instruments brand battery management chip was selected. * Added a boost converter to allow different voltage batteries. * New Portescap brand two-phase generator with 90% efficiency and peak power of 4.5 Watts was selected. #crank#beechat

Видеотека 📼

@videotekashow · Post #14048 · 26.07.2025 г., 18:17

«Вообще, фильм «Карты, деньги, два ствола» был единственной причиной, по которой я поменял профессию». Джейсону Стэйтему сегодня исполнилось 58 лет. #ВИДЕОТЕКА #JasonStatham #LockStockAndTwoSmockingBarrels #Snatch #TheTransporter #Crank #TheExpendables #KillerElite #Safe #Parker #WrathOfMan #AWorkingMan