Python – List Methods & Tasks II

Even though I had done the tasks beforehand, watching them being done in class today taught me new things.

I learned that I could use Python’s in-built list methods more, instead of falling back to for loop all the time.

For example, I could use the …


This content originally appeared on DEV Community and was authored by SM

Even though I had done the tasks beforehand, watching them being done in class today taught me new things.

I learned that I could use Python's in-built list methods more, instead of falling back to for loop all the time.

For example, I could use the extend method (rather than for loop and append method) to expand a list with the contents of another list. Likewise, I could use the clear method (rather than for loop and remove method) to empty a list.

Unless there is a specific need for using the for loop, like I need to check a condition on individual elements before adding them to or removing them from the list, the code looks much cleaner this way.


This content originally appeared on DEV Community and was authored by SM


Print Share Comment Cite Upload Translate Updates
APA

SM | Sciencx (2024-08-01T01:22:45+00:00) Python – List Methods & Tasks II. Retrieved from https://www.scien.cx/2024/08/01/python-list-methods-tasks-ii/

MLA
" » Python – List Methods & Tasks II." SM | Sciencx - Thursday August 1, 2024, https://www.scien.cx/2024/08/01/python-list-methods-tasks-ii/
HARVARD
SM | Sciencx Thursday August 1, 2024 » Python – List Methods & Tasks II., viewed ,<https://www.scien.cx/2024/08/01/python-list-methods-tasks-ii/>
VANCOUVER
SM | Sciencx - » Python – List Methods & Tasks II. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/08/01/python-list-methods-tasks-ii/
CHICAGO
" » Python – List Methods & Tasks II." SM | Sciencx - Accessed . https://www.scien.cx/2024/08/01/python-list-methods-tasks-ii/
IEEE
" » Python – List Methods & Tasks II." SM | Sciencx [Online]. Available: https://www.scien.cx/2024/08/01/python-list-methods-tasks-ii/. [Accessed: ]
rf:citation
» Python – List Methods & Tasks II | SM | Sciencx | https://www.scien.cx/2024/08/01/python-list-methods-tasks-ii/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.