Write python generators below: def shuffle(*args): pass The shuffle generator ta
ID: 3832762 • Letter: W
Question
Write python generators below:
def shuffle(*args):
pass
Explanation / Answer
def shuffle(*args):
word = ""
iter_list = []
for arg in args:
iter_list.append(iter(arg))
while True:
word = ""
for it in iter_list:
try:
word += next(it)
except:
continue
if word == "":
break
yield word
for i in shuffle('abcde', 'fg', 'hijk'):
print(i, end='')
print("")
# code link: https://paste.ee/p/9jJUe
# I am enjoying these generator based question.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.