In the below example I would expect all the elements to be tuples, why is a tuple converted to a string when it only contains a single string?
>>> a = [('a'), ('b'), ('c', 'd')]
>>> a
['a', 'b', ('c', 'd')]
>>>
>>> for elem in a:
... print type(elem)
...
<type 'str'>
<type 'str'>
<type 'tuple'>
Because those first two elements aren’t tuples; they’re just strings. The parenthesis don’t automatically make them tuples. You have to add a comma after the string to indicate to python that it should be a tuple.
To fix your example code, add commas here:
From the Python Docs:
If you truly hate the trailing comma syntax, a workaround is to pass a
listto thetuple()function: