Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# ai-learning
## Python Tip: Use `enumerate()`

Instead of using a loop with a manual index, use `enumerate()`:
18 changes: 5 additions & 13 deletions chatgpt-test.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
# This is a placeholder for AI experiments
print("Hello AI! This is my first AI script.")
# chatgpt-test.py

### Description

# In several Python examples within the project, loops manually track indexes using counters.
# Python provides a built-in function `enumerate()` that simplifies this pattern and improves readability.

### Current pattern

items = ['apple', 'banana', 'cherry']

for i, item in enumerate(items):
print(i, item)
# Example of using enumerate to iterate with index and value
data = ['apple', 'banana', 'cherry']
for index, value in enumerate(data):
print(f"Index: {index}, Value: {value}")