1

If our input was two numbers in a line. And these numbers were greater than 10. How can I make a list out of them by separating them properly? For example:

Input:10 20

X=List(input()):['1','0',' ','2','0']

But i want to be like this:

X=['10',' ','20']
3

2 Answers 2

1

Use str.split:

x = input().split()
print(x)
# ['10', '20']

I assume that you do not want the whitespace separator in between (that is, not ['10', ' ', '20']).

If you need to convert the strings to numeric type, use list comprehension:

x = [int(y) for y in input().split()]
print(x)
# [10, 20]

Then you can do numeric operations such as this, which results in a list with a single element, 20:

x = [y for y in x if y > 10]
print(x)
# [20]
Sign up to request clarification or add additional context in comments.

Comments

1

Try something like this

from sys import argv
print ([int(_) for _ in list(argv[1].split(',')) if int(_) > 10])

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.