diff options
author | Shashwat986 <chandra.shashwat@gmail.com> | 2014-08-05 01:06:54 +0530 |
---|---|---|
committer | Shashwat986 <chandra.shashwat@gmail.com> | 2014-08-05 01:06:54 +0530 |
commit | 65a1b6279fa1038efa013f64d98e7e947b527567 (patch) | |
tree | e7b86525836d7a960ee22236807e6fd6e6e85850 /python.html.markdown | |
parent | a0af5e9a7b0a924cd70e8d3b76f0f9c7eaf0d4d3 (diff) |
Update python.html.markdown
range() is not a generator in python 2.x
Diffstat (limited to 'python.html.markdown')
-rw-r--r-- | python.html.markdown | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/python.html.markdown b/python.html.markdown index 5bec5190..b7d5895a 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -523,11 +523,13 @@ def double_numbers(iterable): # Instead of generating and returning all values at once it creates one in each # iteration. This means values bigger than 15 wont be processed in # double_numbers. -# Note range is a generator too. Creating a list 1-900000000 would take lot of -# time to be made -_range = range(1, 900000000) +# Note xrange is a generator that does the same thing range does. +# Creating a list 1-900000000 would take lot of time and space to be made. +# xrange creates an xrange generator object instead of creating the entire list like range does. +_xrange = xrange(1, 900000000) + # will double all numbers until a result >=30 found -for i in double_numbers(_range): +for i in double_numbers(_xrange): print(i) if i >= 30: break |