laojun001 发表于 2025-2-24 17:23

test01.py

systems = [
    {"book_type": "python", "book_name": "python小册"},
    {"book_type": "python", "book_name": "python学习手册"},
    {"book_type": "python", "book_name": "python编程"},
    {"book_type": "java", "book_name": "java编程实战"},
    {"book_type": "java", "book_name": "java并发编程"},
]
from operator import itemgetter
from itertools import groupby

for book_type, item in groupby(systems, key=itemgetter("book_type")):
    print(book_type)
    for i in item:
      print("", i)
页: [1]
查看完整版本: test01.py