Here is my current code. I would like it to be in one line I don't know how to though so I came here.
if int(input("enter num")) %2 == 0:
print("yay")
Here is my current code. I would like it to be in one line I don't know how to though so I came here.
if int(input("enter num")) %2 == 0:
print("yay")
Since your question wasn't "completely clear". Such as what the output is supposed to be, and if you wanted to compress your code into 1 line or not...
But try this:
#1st code~ returns output like: ['123ello', 'h123llo', 'he123123o', 'he123123o', 'hell123']
#2nd code ~ returns output like: 123123123123123
(@Tim Roberts's comment)
#1
i = input(">");print([i.replace(i[d],"123") for d in range(len(i))])
#2
x = input(">");print('123' * len(i))
#1
i = input(">")
x = []
for d in range(len(i)):
x.append(i.replace(i[d],"123"))
print(x)
#2
x = input(">")
print('123' * len(i))
The following code works with regex. Does it give the desired result?
import re
i = 'i2t'
print(re.sub('[^\W\d_]', '123', i))
The output from above will be: 1232123