import re
dates = '''06-18, 18:00:
06-18, 21:00:
06-19, 00:00:
06-19, 03:00:
06-19, 06:00:
06-19, 09:00:
06-19, 12:00:
06-19, 15:00:
06-19, 18:00:
06-19, 21:00:
06-20, 00:00:
06-20, 03:00:
06-20, 06:00:
06-20, 09:00:
06-20, 12:00:
06-20, 15:00:
06-20, 18:00:
06-20, 21:00:'''
result = ''
last_day = None
for date in dates.split('\n'):
day = re.search(r'\d+-(\d+)', date).group(1)
if day != last_day:
result += '\n{}\n'.format(date)
last_day = day
else:
result += '{}\n'.format(date)
print(result)
import xml.etree.ElementTree as ET
data = '''<?xml version="1.0" encoding="UTF-8"?><response version="1.0"><merchant><id>000000</id><signature>5d7fcffa2290b7ed4ad98ff259d6b79420f01ce5</signature></merchant><data><oper>cmt</oper><info><statements status="excellent" credit="0.0" debet="107.0">
<statement card="012345678910" appcode="00000" trandate="2020-05-15" trantime="13:14:00" amount="92.00 UAH" cardamount="-92.00 UAH" rest="4363.19 UAH" terminal="LIQPAY*Privat24 Androi, I0110UWI" description="Пополнение мобильного +380970000000"/>
<statement card="012345678910" appcode="0000" trandate="2020-05-10" trantime="00:02:00" amount="15.00 UAH" cardamount="-15.00 UAH" rest="4455.19 UAH" terminal="PrivatBank, C400" description="Перевод на карту ПриватБанка через приложение Приват24. Получатель: Іванов Іван Іванович"/>
</statements></info></data></response>'''
root = ET.fromstring(data)
statement = root.find('data/info/statements/statement')
rest = statement.get('rest')
description = statement.get('description')
statements = root.find('data/info/statements')
for statement in statements:
print(statement.get('rest'))
print(statement.get('description'))