User input integer list [duplicate]

Your best way of doing this, is probably going to be a list comprehension.

user_input = raw_input("Please enter five numbers separated by a single space only: ")
input_numbers = [int(i) for i in user_input.split(' ') if i.isdigit()]

This will split the user’s input at the spaces, and create an integer list.

Browse More Popular Posts

Leave a Comment