a.replace("(", "").replace(")", "")
Well, yes. All you are doing here, is removing some chars (parenthesis, but those are just chars in this context) from a string.
So, on each string "(One, 1)"
you apply a conversion to get a string "One, 1"
.
Then, you put that string in a list
[a.replace("(", "").replace(")", "")]
So, what you get is just the list containing that string: ["One, 1"]
That you convert into a tuple
tuple([a.replace("(", "").replace(")", "")])
So ("One, 1",)
instead of ["One, 1"]
. Just a tuple containing a single string.
Apparently, what you wanted was to split that string into substring, because of the coma.
a.replace("(", "").replace(")", "").split(',')
To get a list ['One', ' 1']
.
And then transform this into a tuple, and append it
tuple(a.replace("(", "").replace(")", "").split(','))
→ ('One', ' 1')
So, altogether
[tuple(a.replace("(", "").replace(")", "").split(',')) for a in list1]
Your "wanted" result shows that, in addition, you want to parse the second part of each tuple to get an int
So
for a in list1:
x,y=a.replace("(", "").replace(")", "").split(' ')
list2.append((x, int(y)))
Note, that there is no more "tuple" here, because it is explicitly created from x and y, that I had to explicitly name, to be able to convert one of them
Also note that I did not need to strip the space you probably noticed in that second part of the tuple, because conversion to int took care of it. Ortherwise, you would have needed a more complex split, (or an explicit strip) to ensure that there is no spaces included in the two parts)
Last note: avoid naming variables "list" (or, "str" for that matter :)). Those are predefined symbols. You can overwrite them, sure, since they are not keywords, but, you are not supposed to. They are pretty important part of the language, and strange things may happen in your code if you change the meaning of "list" or "str".