Python convert list values to int values

 

I have a list with int values as strings as following:

>>> mylist = ['1', '2', '3', '4']

>> mylist

['1', '2', '3', '4']

I would like to convert all values in mylist to int’s.

I used following code to convert values of lists to int’s:

>>> output = map(int, mylist)

>>> output

[1, 2, 3, 4]

Now just observer both list output values, all values in mylist are strings and all values in output list are int’s.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s