Usually, to detect a string field, I can just check to see if the first char is a string. For example:
>>> [str(v)[0].isalpha() for v in ['first', 'last']]
[True, True]
However, sometimes I'll have database or other fields that are strings, but start with a number, for example "3D" is a field I've come across.
What would be the most performant way to check to see if all items in a list are strings?
Here are some examples:
['1.0', 'test', '3d', '123,000.00', '55']
> False, True, True, False, False
Basically, I want to know if a value can be stored as a varchar field or needs to be converted to a non-string field.
It would be something like:
values = ['1.0', 'test', '3d', '123,000.00', 55]
>>> [not re.sub(r'\,|\.', '', str(val)).isdigit() for val in values]
[False, True, True, False, False]
Are there better ways to do this?