Python
- 12 ответов
- 0 вопросов
16
Вклад в тег
"Explicit is better than implicit."
import json
def model_by_plate(js, plate):
for car in json.loads(js)['cars']:
if car['plate'] == plate:
return car['model']
print(model_by_plate(data, 'E222EE177'))
from collections import defaultdict
def_dic = defaultdict(int)
for c in text:
def_dic[c] += 1
import csv
import xml.etree.ElementTree as ET
xml_data = """<?xml version="1.0"?>
<Root>
...
</Root>"""
root = ET.fromstring(xml_data)
header = set()
rows = []
for subroot in root:
row = {}
for level in subroot:
header.add(level.tag)
row[level.tag] = level.text
rows.append(row)
with open('out.csv', 'w') as file:
writer = csv.DictWriter(file, fieldnames=sorted(header))
writer.writeheader()
writer.writerows(rows)