Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一组 Tag 对象
list [<Tag: Sport>, <Tag:Sport>]
每个 Tag 对象都包含另一个称为“Blog”对象的对象。
将列表从标记对象列表更改为博客对象列表的最有效方法是什么,其中每个标记对象条目都更改为其对应的博客对象?以便
list [<Blog: ManU beats Liverpool>, <Blog: Barca or RealMadrid>]
blog_list = [tag.blog for tag in tag_list]
或到位:
for i, tag in enumerate(tag_list): tag_list[i] = tag.blog
有地图
map(lambda item: item.blog, tag_list)