What is the easiest way to convert a list of strings to a list of numbers so that those that look like integers converts to int and others to float?
Example:
list = ['1' , '2.2' , '3']
One way to convert is to define are they ints or floats:
list = [float(item) for item in list]
But in this example also obvious int would be converted to float as well.
One way could be to check variable type and convert case by case. Is there an easier way?
Edit:
A similar looking question How can I convert a string to either int or float with priority of int is a little hard to understand what the questions is, and accepted answer does not cover my case.
Another similar looking question How do I parse a string to float or int in Python is a basic question of how to convert to int or float and my question went a little further than that.
I'll ask again in other words: How to convert a string (or list of strings) to just to a number (or list of numbers), whatever type, retain its type whether int, float (or complex). Usually conversion is made from string to a certain type of number, usually to int or float. Is there an easy and obvious way to convert a string to a number of any kind?