I have a list which looks something like this:
[\'1\', \'2\', \'3.4\', \'5.6\', \'7.8\']
How do I change the first two to int
int
Use isdigit method of string:
numbers = [int(s) if s.isdigit() else float(s) for s in numbers]
or with map:
numbers = map(lambda x: int(x) if x.isdigit() else float(x), numbers)