标签: python
我最好的尝试失败了:
for s in self.services: for m in s.messages: yield m
答案 0 :(得分:7)
(m for s in self.services for m in s.messages)
......看起来像反直觉一样。
答案 1 :(得分:3)
itertools.chain.from_iterable(s.messages for s in self.services)