5

how to convert strings to integers in a list?

 1 year ago
source link: https://www.codeabbey.com/index/forum_topic/215de5acddb98c1c6fe9d4b036640c48
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

how to convert strings to integers in a list?

Back to General discussions forum

itzzner     2022-05-17 22:56:32

in the last exercises I have done I have tried to find the most optimal way to pass a list of strings to a list of integers, the best I have been able to do is the following: entry = [int (x) for x in input().split()] How else could you use this conversion?

Moff     2022-05-18 05:51:02
User avatar

List comprehension [int (x) for x in input().split()] is good way for Python. Another approach is using map function: list(map(int, s.split()))

Please login and solve 5 problems to be able to post at forum

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK