Search code examples
pythonstringinteger

How to convert String into integers in python sickit-learn


I have a list as above:

probs= ['2','3','5','6']

and i want to convert those string to a numeric values like the following result:

resultat=[2, 3, 4, 5, 6]

I tried some solutions appearing on this link: How to convert strings into integers in Python? such as this one:

new_list = list(list(int(a) for a in b) for b in probs if a.isdigit())

but it didn't work, someone can help me to adapt this function on my data structure, i will be really thankful.


Solution

  • >>> probs= ['2','3','5','6']
    >>> probs= map(int, probs)
    >>> probs
    [2, 3, 5, 6]
    

    or (as commented):

    >>> probs= ['2','3','5','6']
    >>> probs = [int(e) for e in probs]
    >>> probs
    [2, 3, 5, 6]
    >>>