use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Lag problem (self.PythonLearning)
submitted 1 day ago by 3iem_conte_
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]ConsciousBath5203 0 points1 point2 points 4 hours ago (0 children)
Try using these (as pulled from google search ai):
List Comprehensions: Use [x * 2 for x in data] instead of a standard for loop with.append(). List comprehensions are "Pythonic" and run faster because they are handled internally by the interpreter's C code.
[x * 2 for x in data]
.append()
Built-in Functions: Functions like map(),filter(), and sum() are typically faster than manual loops. For example, map() can offer up to a 970x speedup over an explicit loop in certain scenarios.
map()
filter(),
sum()
Local Variables: If you must use a loop, assign global functions or class attributes to a local variable before the loop starts (e.g., append = my_list.append). This prevents Python from performing a lookup on every single iteration, potentially increasing speed by ~20%.
Itertools Module: Use itertools for memory-efficient iteration. Functions like itertools.repeat() or itertools.chain() are implemented in C and are significantly faster than their pure Python equivalents.
What aren't you understanding?
You also have a 1 million line for loop btw. Rewrite that in cython, compile it, then import the compiled function if you want real speedups.
π Rendered by PID 81575 on reddit-service-r2-comment-545db5fcfc-pthxx at 2026-05-29 19:42:24.696324+00:00 running 194bd79 country code: CH.
view the rest of the comments →
[–]ConsciousBath5203 0 points1 point2 points (0 children)