Home > Software engineering >  Convert list to string in python such that it separates the each integer as an element
Convert list to string in python such that it separates the each integer as an element

Time:07-27

I have a list

f=['20.0', '21.0', '22.0', '23.0', '24.0', '25.0', '26.0', '27.0',
   '28.0', '29.0', '30.0', '31.0', '32.0', '33.0']

I want to change the list to string such that each element is recognized as an integer 20 21... That is f[0]=20, f[1]=21. If I just use f=str(f), then it will count [' as an element too.

CodePudding user response:

Is this what you mean?

f = list(map(lambda x : int(float(x)), f))

if you want the list to still contain elements of type string instead of int just do it like this:

f = list(map(lambda x : str(int(float(x))), f))

CodePudding user response:

f = [float(element) for element in f]
  • Related