diff --git a/README.md b/README.md index 5909942..58ff2e0 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -# ai-learning \ No newline at end of file +## Python Tip: Use `enumerate()` + +Instead of using a loop with a manual index, use `enumerate()`: \ No newline at end of file diff --git a/chatgpt-test.py b/chatgpt-test.py index ef0af7b..9c1c842 100644 --- a/chatgpt-test.py +++ b/chatgpt-test.py @@ -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) \ No newline at end of file +# 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}") \ No newline at end of file