feat: 新增技能扩展N5一章相关示例源码
This commit is contained in:
22
code/newsletter/N5/generator.py
Normal file
22
code/newsletter/N5/generator.py
Normal file
@@ -0,0 +1,22 @@
|
||||
def make_cards(values):
|
||||
container = values or []
|
||||
for value in container:
|
||||
yield value
|
||||
|
||||
|
||||
def main():
|
||||
from collections.abc import Generator
|
||||
|
||||
cards = make_cards(list("JQK"))
|
||||
print(cards)
|
||||
|
||||
print(f"Is the cards variable a generator? {isinstance(cards, Generator)}")
|
||||
for card in cards:
|
||||
print(card)
|
||||
|
||||
results = list(cards)
|
||||
print(results)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user