- 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

20th Mar 2021, 1:54 AM
Rohan Raj Shrestha
Rohan Raj Shrestha - avatar
5 odpowiedzi
+ 3
print(list("".join(input().split())))
20th Mar 2021, 3:04 AM
David Ashton
David Ashton - avatar
+ 3
use strip(); Example : str = "['1', ' ', '+', ' ', '1']" res = str.strip(); print(res)
20th Mar 2021, 2:07 AM
BITTU BENNY
BITTU BENNY - avatar
+ 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()
20th Mar 2021, 2:08 AM
visph
visph - avatar
+ 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
20th Mar 2021, 11:24 AM
iTech
iTech - avatar
0
Need help for a program anyone
20th Mar 2021, 3:45 AM
Rohan Raj Shrestha
Rohan Raj Shrestha - avatar