1

The input is something like: "W,79,V,84,U,63,Y,54,X,91"

Output should be: [‘W’, ‘79’, ‘V’, ‘84’ , ‘U’, ‘63’, ‘Y’, ‘54’, ‘X’, ‘91’]

but my code is filled with comma.

a1 = list(input())
print(a1)

my output is ['W', ',', '7', '9', ',', 'V', ',', '8', '4', ',', 'U', ',', '6', '3', ',', 'Y', ',', '5', '4', ',', 'X', ',', '9', '1']

How do I remove the commas? Note :cant use build in functions except input(), split(), list.append(), len(list), range(), print()

MegaIng
  • 7,361
  • 1
  • 22
  • 35
RYUGA677
  • 13
  • 4

3 Answers3

7

You have to split the input using input().split(',').

a1=input().split(',')
print(a1)
Marc Sances
  • 2,402
  • 1
  • 19
  • 34
1

@MarcSances answered your question. But if you just want to remove the commas from the list just use this

a1 = [x for x in list(input()) if x != ',']
print(a1)

Or do it in 3 lines

user_input = list(input())
a1 = [x for x in user_input if x != ',']
print(a1)
AM Z
  • 423
  • 2
  • 9
0

Best way to do this in python

#Devil
your_input = input()
lst = your_input.split(",")
print("output:", lst)
# output : ['W', '79', 'V', '84', 'U', '63', 'Y', '54', 'X', '91']
Devil
  • 1,054
  • 12
  • 18