From 2486fa8c1e51e975c603fa7972542deae287817b Mon Sep 17 00:00:00 2001 From: Mariusz Skoneczko Date: Tue, 22 Oct 2019 12:08:08 +1100 Subject: [python3/en] Clarify difference between iterators and iterables in the last example (closes #3586) --- python3.html.markdown | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'python3.html.markdown') diff --git a/python3.html.markdown b/python3.html.markdown index 430927a9..61c53408 100644 --- a/python3.html.markdown +++ b/python3.html.markdown @@ -550,8 +550,14 @@ next(our_iterator) # => "three" # After the iterator has returned all of its data, it raises a StopIteration exception next(our_iterator) # Raises StopIteration -# You can grab all the elements of an iterator by calling list() on it. -list(filled_dict.keys()) # => Returns ["one", "two", "three"] +# We can also loop over it, in fact, "for" does this implicitly! +our_iterator = iter(our_iterable) +for i in our_iterator: + print(i) # Prints one, two, three + +# You can grab all the elements of an iterable or iterator by calling list() on it. +list(our_iterable) # => Returns ["one", "two", "three"] +list(our_iterator) # => Returns [] because state is saved #################################################### -- cgit v1.2.3 From 49a7c2dd3b38df21e5844b2d9b03067d2c910acf Mon Sep 17 00:00:00 2001 From: caminsha Date: Thu, 14 Nov 2019 00:11:02 +0100 Subject: Fixed typo: uptil => until --- python3.html.markdown | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'python3.html.markdown') diff --git a/python3.html.markdown b/python3.html.markdown index 61c53408..d09c2819 100644 --- a/python3.html.markdown +++ b/python3.html.markdown @@ -8,6 +8,7 @@ contributors: - ["evuez", "http://github.com/evuez"] - ["Rommel Martinez", "https://ebzzry.io"] - ["Roberto Fernandez Diaz", "https://github.com/robertofd1995"] + - ["caminsha", "https://github.com/caminsha"] filename: learnpython3.py --- @@ -230,7 +231,7 @@ li[4] # Raises an IndexError # (It's a closed/open range for you mathy types.) li[1:3] # Return list from index 1 to 3 => [2, 4] li[2:] # Return list starting from index 2 => [4, 3] -li[:3] # Return list from beginning uptil index 3 => [1, 2, 4] +li[:3] # Return list from beginning until index 3 => [1, 2, 4] li[::2] # Return list selecting every second entry => [1, 4] li[::-1] # Return list in reverse order => [3, 4, 2, 1] # Use any combination of these to make advanced slices -- cgit v1.2.3