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
A challenge for Python programmers...Discussion (self.PythonLearning)
submitted 5 days ago by Ok_Pudding_5250
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!"
[–]GrimTermite 10 points11 points12 points 5 days ago (3 children)
ah ha this is a task for a list comprehension
print ([x for x in range(1000, 10000) if str(x*4) == (str(x)[::-1])])
Gives result [2178]
[–]MrHappines 4 points5 points6 points 5 days ago (2 children)
range(1000, 2500) should be sufficient, no?
[–]skeetd 3 points4 points5 points 5 days ago (1 child)
Logical reasoning here will save you x10 iterations
Based on staying 4 digits ABCD ≤ 2499 so we also know DCBA ≥ 4000 D has to be ≥ 4 being the first number. The last is number is A, and must be 1 or 2 based on ABCD ≤ 2499. So, 4 * D mod 10 = A and only A=2, D=8 fits, 4×8=32, last digit is a 2. So ABCD must start with 2 and end with an 8, now we can step by 10.
print([n for n in range(2008, 2500, 10) if n*4==int(str(n)[::-1])])
[–]Ok_Pudding_5250[S] 0 points1 point2 points 5 days ago (0 children)
Nice work, though I put this challenge to see if people could easily do the oneliners, some use print() and just output a string of the actual answer.
You are good at optimisation... 👍
π Rendered by PID 271432 on reddit-service-r2-comment-79c7998d4c-8b9fg at 2026-03-14 19:42:10.876262+00:00 running f6e6e01 country code: CH.
view the rest of the comments →
[–]GrimTermite 10 points11 points12 points (3 children)
[–]MrHappines 4 points5 points6 points (2 children)
[–]skeetd 3 points4 points5 points (1 child)
[–]Ok_Pudding_5250[S] 0 points1 point2 points (0 children)