From bf4d1d7d96c20ba32eb0fce37c2e2dd1fc0b2518 Mon Sep 17 00:00:00 2001 From: loganionian <103104454+loganionian@users.noreply.github.com> Date: Fri, 6 Feb 2026 00:18:52 +0800 Subject: [PATCH 1/4] Use enumerate() for cleaner loops in chatgpt-test.py --- chatgpt-test.py | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/chatgpt-test.py b/chatgpt-test.py index ef0af7b..c1ba869 100644 --- a/chatgpt-test.py +++ b/chatgpt-test.py @@ -1,14 +1,8 @@ -# This is a placeholder for AI experiments -print("Hello AI! This is my first AI script.") - -### 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 +# chatgpt-test.py +def some_function(): + data = ['apple', 'banana', 'cherry'] + for index, value in enumerate(data): + print(index, value) + +if __name__ == "__main__": + some_function() \ No newline at end of file From 813fda599e568e8686b4f174f8480289a00eb4a5 Mon Sep 17 00:00:00 2001 From: loganionian <103104454+loganionian@users.noreply.github.com> Date: Fri, 6 Feb 2026 12:31:26 +0800 Subject: [PATCH 2/4] Add example of using enumerate() in loops --- chatgpt-test.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/chatgpt-test.py b/chatgpt-test.py index c1ba869..d9c5b6c 100644 --- a/chatgpt-test.py +++ b/chatgpt-test.py @@ -1,8 +1,7 @@ -# chatgpt-test.py -def some_function(): - data = ['apple', 'banana', 'cherry'] - for index, value in enumerate(data): - print(index, value) +def loop_with_enumerate(): + items = ['apple', 'banana', 'cherry'] + for index, value in enumerate(items): + print(f'Index: {index}, Value: {value}') -if __name__ == "__main__": - some_function() \ No newline at end of file +# Call the function to demonstrate its usage +loop_with_enumerate() \ No newline at end of file From 26c0def09906f75bff1989b09ff2af43bb0d2cce Mon Sep 17 00:00:00 2001 From: loganionian <103104454+loganionian@users.noreply.github.com> Date: Fri, 6 Feb 2026 12:31:27 +0800 Subject: [PATCH 3/4] Add example of using enumerate() in loops --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 From 7e457c7b6f8d0e9fbb2c8c548d5c8d70e1f9e691 Mon Sep 17 00:00:00 2001 From: loganionian <103104454+loganionian@users.noreply.github.com> Date: Mon, 9 Feb 2026 16:30:30 +0800 Subject: [PATCH 4/4] Enhance example to use enumerate() for index and value --- chatgpt-test.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/chatgpt-test.py b/chatgpt-test.py index d9c5b6c..9c1c842 100644 --- a/chatgpt-test.py +++ b/chatgpt-test.py @@ -1,7 +1,6 @@ -def loop_with_enumerate(): - items = ['apple', 'banana', 'cherry'] - for index, value in enumerate(items): - print(f'Index: {index}, Value: {value}') +# chatgpt-test.py -# Call the function to demonstrate its usage -loop_with_enumerate() \ 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