Reputation: 129
For e.g. user input:
4,7,5,33,2,8
should give output like this:
['4', '7', '5', '33', '2', '8'] ('4', '7', '5', '33', '2', '8')
So far i have this:
x = input()
z = x.split()
y = tuple(z)
print(z, y)
why there is extra , in the end of tuple?
Upvotes: 0
Views: 260
Reputation: 8273
The extra comma is because the string you tried to split is not what you are expecting after the split. Since the split was performed on space with x.split()
and string does not have white space so after the step the string is still a single string and then list
and tuple
just wrap the string and that's where the extra comma is coming from. Example tuple('a') == ('a',)
x.split(',')
will create a list separate by comma and will fetch you expected results
Upvotes: 1