Skip to content

Instantly share code, notes, and snippets.

@XanderVi
Created September 4, 2018 16:02
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 XanderVi/aebd649fd228277749f00381d61c0452 to your computer and use it in GitHub Desktop.
Save XanderVi/aebd649fd228277749f00381d61c0452 to your computer and use it in GitHub Desktop.
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