- 1
I need help to remove spaces form list. For example user gives input as 1 + 1.
We input list ['1', ' ', '+', ' ', '1'] I need to remove these space in between if possible without loop
5 odpowiedzi
+ 3
print(list("".join(input().split())))
+ 3
use strip();
Example :
str = "['1', ' ', '+', ' ', '1']"
res = str.strip();
print(res)
+ 3
input() return a string
I guess you're make the list with:
list = input().split(' ')
but you will get what you expect by simply doing:
list = input().split()
+ 1
its you who restrict the user how the input should be!
you can do it with try except block.
https://www.w3schools.com/JUMP_LINK__&&__python__&&__JUMP_LINK/python_try_except.asp
0
Need help for a program anyone