Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f8ff933

Browse files
Merge pull request #37 from majvax/main
[find file/python] fixed snippet perf issue
2 parents bb7320d + 719605f commit f8ff933

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

‎public/data/python.json

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,13 @@
187187
"import os",
188188
"",
189189
"def find_files(directory, file_type):",
190-
" file_type = file_type.lower() # Convert file_type to lowercase",
191-
" found_files = []",
190+
" file_type = file_type.lower()",
191+
" found_files = []",
192192
"",
193-
" for root, _, files in os.walk(directory):",
194-
" for file in files:",
195-
" file_ext = os.path.splitext(file)[1].lower()",
196-
" if file_ext == file_type:",
197-
" full_path = os.path.join(root, file)",
198-
" found_files.append(full_path)",
199-
"",
200-
" return found_files",
193+
" for entry in os.scandir(directory):",
194+
" if entry.is_file() and entry.name.lower().endswith(file_type):",
195+
" found_files.append(entry.name)",
196+
" return found_files",
201197
"",
202198
"# Example Usage:",
203199
"pdf_files = find_files('/path/to/your/directory', '.pdf')",

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /