File tree Expand file tree Collapse file tree 1 file changed +25
-2
lines changed
Expand file tree Collapse file tree 1 file changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -118,6 +118,29 @@ multiple items from another list and remove removes an item.
118118>> >
119119```
120120
121+ Note that ` remove ` removes only the first match it finds.
122+
123+ ``` py
124+ >> > names = [' theelous3' , ' go|dfish' , ' theelous3' ]
125+ >> > names.remove(' theelous3' )
126+ >> > names # the second theelous3 is still there!
127+ [' go|dfish' , ' theelous3' ]
128+ >> >
129+ ```
130+
131+ If we need to remove all matching items we can use a simple while loop.
132+ We'll talk more about loops [ in the next chapter] ( loops.md ) .
133+
134+ ``` py
135+ >> > names = [' theelous3' , ' go|dfish' , ' theelous3' ]
136+ >> > while ' theelous3' in names:
137+ ... names.remove(' theelous3' )
138+ ...
139+ >> > names
140+ [' go|dfish' ]
141+ >> >
142+ ```
143+
121144We can also use slicing and indexing to change the content:
122145
123146``` py
@@ -186,7 +209,7 @@ False
186209>> >
187210```
188211
189- If we need a new list with the same content we can use the
212+ If we need ** a new list with similar content** we can use the
190213` copy ` method.
191214
192215``` py
@@ -242,7 +265,7 @@ used in places like `(1 + 2) * 3`.
242265```
243266
244267Tuples don't have methods like append, extend and remove
245- because they can't change theirselves in-place.
268+ because they can't change themselves in-place.
246269
247270``` py
248271>> > stuff = (1 , 2 , 3 )
You can’t perform that action at this time.
0 commit comments