Is there a way to tell whether, in python, you are iterating through a list or a generator?
for i in range(10):
print some_param # will identify as a list
for i in xrange(10):
print some_param # will identify as a generator
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In general, no. You can do unpleasant things like
isinstance(my_iterable, type(iter(xrange(1))))vsisinstance(my_iterable, type(iter([]))), but with the bare iterator interface, generators and lists are indistinguishable to their clients.