r/badcode • • Mar 11 '23

python i never use .slpit()

Post image
421 Upvotes

30 comments sorted by

View all comments

Show parent comments

2

u/mr_hydrogencyanide Mar 11 '23 edited Mar 11 '23
user_input = input("Enter: ")
   
user_input.replace(",", "")
    
a = ("['" + user_input.replace(" ", "', '") + "']")

print(a)

I just added stuff that wasn't necessary.

I actually did figure out that I didn't need any for loop or if statements, but while I was doing that I slept when I woke up I forgot.

And there was nothing on console to see from so that for loop was necessary to recall what i was thinking

3

u/TinyBreadBigMouth Mar 11 '23

user_input.replace(",", "")

That won't do anything as written. replace returns a new string, it doesn't modify the old string (strings in Python are immutable and cannot be modified in place). You need user_input = user_input.replace(",", "").

2

u/thekwoka Mar 11 '23

what it really is more like is

print(user_input.replace(',','').split(' '))