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 слични објави

Пребарај: #peptides

当前筛选 #peptides清除筛选
Venture Village Wall 🦄

@venturevillagewall · Post #3629 · 21.12.2024 г., 10:22

$4.07M Funding for PeptiSystems PeptiSystems secured $4.07M in funding on December 20, 2024. The company develops advanced instruments for solid-phase synthesis in peptide and oligonucleotide therapeutics, catering to both GMP and non-GMP manufacturing. Discover more: PeptiSystems #Funding#PeptiSystems#Therapeutics#Peptides#Oligonucleotides#GMP#Manufacturing#Synthesis#Biotechnology#Pharmaceuticals#MedicalDevices#FlowthroughColumnTechnology#ProcessDevelopment#LifeSciences

Venture Village Wall 🦄

@venturevillagewall · Post #3665 · 21.12.2024 г., 11:00

Funding News: December 2024 🚀 Major funding rounds announced: - Alvie: $2.19M for HUGO digital assistant - Buildpeer: $2.50M for construction project optimization - Island Passage: $2.50M in funding - TIXiMED: $2.65M for diabetes treatment - The Pad Climbing: $3M for climbing community project - PeptiSystems: $4.07M for peptide and oligonucleotide therapeutics - Greenlight Health: $4.20M for data solutions - TripSuite: $5M for agency growth tools - DuckChain: $5M for blockchain solutions - Nexa Finance: $5.04M for investment opportunities - Tenor: $5.40M for management training with AI - Smartr365: $6.33M for mortgage brokerage platform - Astraveus: $7.40M for cell therapies - EditPep: $8.20M in funding - Jrnys: $8.65M for personalized healthcare solutions - Hoji: $8.94M for ecological solutions - Hauler Hero: $10M for waste management software - Trinity College, Dublin: $10.46M in funding - PeproMene Bio: $11M for cancer therapies - Hervolution Therapeutics: $11.70M for immunotherapies For more details, visit the respective websites. #Funding#Healthcare#Biotech#AI#Construction#Therapeutics#WasteManagement#Investment#DigitalAssistant#CellTherapies#EcoDesign#Mortgage#Finance#Diabetes#Peptides#Community#Climbing#Software#PersonalizedHealthcare#Blockchain