this post was submitted on 21 Jul 2025
9 points (100.0% liked)

Programming Horror

222 readers
2 users here now

Share strange or straight-up awful code.

founded 2 years ago
MODERATORS
 

"maybe I shouldn't have learned programming from youtube tutorials..."

it's supposed to turn a list (e.g. [1, 2, 3, 4, 1, 0] ) into [1, 2, 3, 4, 10]

it actually works (for my use-case, anyways) but is completely ridiculous and I'm about to remove it in favor of bypassing this problem entirely

text code if you want:

newplant = [1, 2, 3, 4, 1, 0] # can be a list of any positive int with a 0 before another number
for number in newplant:
            if number == 0:
                newplant[(newplant.index(0) - 1):(newplant.index(0) + 1)] = [int(''.join(str(v) for v in [newplant[(newplant.index(0) - 1)], 0]))]
top 1 comments
sorted by: hot top controversial new old
[–] JackbyDev@programming.dev 1 points 4 months ago

Why did you have a list like that in the first place lol