Вот файл CSV.
Код: Выделить всё
Harry,Number Four,Privet Drive
Ron,The Burrow
Draco,Malfoy Manor
Вот код Python.
Код: Выделить всё
import csv
students = []
with open("students.csv") as file:
reader = csv.reader(file)
for row in reader:
students.append({"name": row[0], "home": row[1]})
for student in sorted(students, key=lambda student: student["name"]):
print(f"{student['name']} is from {student['home']}")
Код: Выделить всё
Draco is from Malfoy Manor
Harry is from Number Four
Ron is from The Burrow
Подробнее здесь: https://stackoverflow.com/questions/788 ... ted-output