Skip to content

Instantly share code, notes, and snippets.

@scandiumby
Created May 15, 2022 08:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scandiumby/cad2c7271bc94c918ba028ccd33fa9f6 to your computer and use it in GitHub Desktop.
Save scandiumby/cad2c7271bc94c918ba028ccd33fa9f6 to your computer and use it in GitHub Desktop.
Gurtam's task in PyCon By 2020
import asyncio
import string
class CharIterator:
def __init__(self):
self.pos = 0
def __aiter__(self):
return self
async def __anext__(self):
while self.pos < len(string.ascii_lowercase):
self.pos += 1
char = string.ascii_lowercase[self.pos - 1]
if self.pos == 7:
return char.capitalize()
elif self.pos in (21, 18, 20, 1, 13):
return char
def char_pos_gen():
char_pos = [4, 0, 5, 2, 3, 1]
for pos in char_pos:
yield pos
async def main():
dw = {}
cpg = char_pos_gen()
async for char in CharIterator():
try:
dw[next(cpg)] = char
except StopIteration:
break
res = ''
for n in sorted(dw):
res += dw[n]
print(res)
if __name__ == '__main__':
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(main())
finally:
loop.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment