Python: Loop Thru List

By Xah Lee. Date: . Last updated: .
# python 3

aa = [1,2,3, "∞"]

for xx in aa:
    print(xx)

# 1
# 2
# 3
# 

get both index and value.

# python 3

bb = ['one', 'two', 'three', 'infinity']

for ii, vv in enumerate(bb):
    print(ii, vv)

# 0 one
# 1 two
# 2 three
# 3 infinity

Python Lisp Topic

  1. List Basics
  2. Loop Thru List
  3. Map Function to List
  4. List Comprehension
  5. List Methods

If you have a question, put $5 at patreon and message me.

Python

  1. Python 3 Basics
  2. Python 2 Basics
  3. Python 2 and 3 Difference
  4. Print Version
  5. Builtin Help
  6. Quote String
  7. String Methods
  8. Format String
  9. Operators
  10. True, False
  11. if then else
  12. Loop
  13. List Basics
  14. Loop Thru List
  15. Map f to List
  16. List Comprehension
  17. List Methods
  18. Sort
  19. Dictionary
  20. Loop Thru Dict
  21. Dict Methods
  22. Function
  23. Class
  24. Object, ID, Type
  25. List Modules
  26. Write a Module
  27. Unicode 🐍

Regex

  1. Regex Basics
  2. Regex Reference

Text Processing

  1. Read/Write File
  2. Traverse Directory
  3. 2 Traverse Directory
  4. File Path
  5. Process Unicode
  6. Convert File Encoding
  7. Find Replace in dir
  8. Find Replace by Regex
  9. Count Word Frequency

Web

  1. Send Email
  2. GET Web Page
  3. Web Crawler
  4. HTTP POST

Misc

  1. JSON
  2. Find Script Path
  3. Get Env Var
  4. System Call
  5. Decompress Gzip
  6. Complex Numbers
  7. Copy Nested List
  8. Tuple vs List
  9. Sets, Union, Intersection
  10. Closure
  11. 2 Closure
  12. Decorator
  13. Append String in Loop
  14. Timing f timeit
  15. Keyword Arg Default Value Unstable
  16. Check Page Load Size
  17. Thumbnail Generation