0

On a project I am currently getting returned a list as follows:

[u'40620', u'00700', u'24150', u'11700']

How can I edit the list so it is returned just integer values:

[40620, 00700, 24150, 11700]

Thanks!

1
  • 00700 is not a valid integer value. Commented Mar 3, 2014 at 2:10

2 Answers 2

2

Use a list comprehension and int:

>>> lst = [u'40620', u'00700', u'24150', u'11700']
>>> [int(x) for x in lst]
[40620, 700, 24150, 11700]
>>>
Sign up to request clarification or add additional context in comments.

2 Comments

The Py3 example would work in Python 2 as well, and is recommended
@michel-slm - Eh, why not. I'll let Cygwinnian have the map solution. :)
1

Simple one liner:

results = map(int, results)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.