Created
March 22, 2019 15:59
-
-
Save komuw/bea09b4de273424e2c4acb600d49d346 to your computer and use it in GitHub Desktop.
convert list to iterable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import collections | |
class Iterable: | |
def __init__(self, my_list): | |
self.pool = collections.deque(my_list, maxlen=None) | |
self.len = len(self.pool) | |
self.index = 0 | |
def __aiter__(self): | |
return self | |
async def __anext__(self): | |
self.index += 1 | |
if self.index > self.len: | |
raise StopAsyncIteration | |
return self.pool.popleft() | |
async def cool(): | |
async for i in Iterable(my_list=["AA", 1, 2, 3, 5, "ZZ"]): | |
print(i) | |
asyncio.run(cool()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
python hello.py