Created
September 4, 2018 16:02
-
-
Save XanderVi/aebd649fd228277749f00381d61c0452 to your computer and use it in GitHub Desktop.
This file contains 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
a = [1, [2, 2, 2], 4] | |
def flat_list(x): | |
return iter(x) | |
def make_iter(data): | |
for i in range(len(data)): | |
if type(data[i]) == list: | |
data[i] = make_iter(data[i]) | |
data[i] = iter(data[i]) | |
return data | |
def cover(func, in_data): | |
res = func(iter(make_iter(in_data))) | |
assert hasattr(res, '__iter__'), "your function should return the iterator object" | |
assert hasattr(res, '__next__'), "your function should return the iterator object" | |
return list(res) | |
z = cover(flat_list, a) | |
print(list(z)) | |
print(list(z[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment