Python Forum
How to remove extra space from output list?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to remove extra space from output list?
#1
Hi,

I have this input
P (0, 2,+1) (2, 0, -1) (0, 4,+1) (4, 0, -1)
and I would like to have it printed out this way
[(0, 2, 1), (2, 0, -1), (0, 4, 1), (4, 0, -1)]
. However, due to the extra space in the input I ran into this error. Without making any change to the input, I wonder if anyone could advise? Thanks
    algorithm_type_2 = list(eval(user_input_2))
  File "<string>", line 1
    (0,,2,+1),(2,,0,,-1),(0,,4,+1),(4,,0,,-1)
       ^
SyntaxError: invalid syntax
user_input = input().split()
# input_list = user_input.split()
# algorithm_type = 'X'
algorithm_type = user_input.pop(0)

user_input_2 = ','.join(user_input)
algorithm_type_2 = list(eval(user_input_2))
print(user_input_2)
print(algorithm_type_2)
Reply


Messages In This Thread
How to remove extra space from output list? - by longmen - May-05-2022, 03:12 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Exercise list remove duplicates RavCOder 9 5,393 Oct-23-2019, 04:16 PM
Last Post: jefsummers
  Removing extra space sumncguy 4 2,935 Jun-07-2019, 09:16 PM
Last Post: sumncguy
  Remove special character from list vestkok 3 4,347 Nov-04-2018, 01:48 PM
Last Post: ichabod801
  "List index out of range" for output values pegn305 3 5,402 Nov-26-2017, 02:20 PM
Last Post: heiner55
  Functions to remove vowels and extra blanks RiceGum 10 6,008 Nov-17-2017, 05:40 PM
Last Post: heiner55
  How to keep duplicates and remove all other items in list? student8 1 5,042 Oct-28-2017, 05:52 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020