I want to pass values in a single line with spaces ex:- 2 3 1 1 1. 2 should be assigned to A , 3 should be assigned to B and the remaining numbers should be assigned to a list .How can I do it? I tried A,B,C = map(int, input ().split()) but it shows error
1/23/2022 12:51:03 PM
syed fahad8 Answers
New AnswerTry A, B, *C = map(..blah blah...), If not got my ide up and running at the moment and it's been a while since I've done any python.
If only the last values are int, you could try to only convert the non-string variables: a, b, *c = input().split() a, b = int(a), int(b)
you have to prefix C with * like *C so that it can assign the rest of the numbers, as it is variable. So: A,B,*C = map(int, input().split()) without it it would throw an error because the rest has not been assigned
n = int(Input ()) ls = list(n.split()) A = ls[0] B = ls[1] simplest one, don't go for mapped ,zip functions it will only drain your brain's battery
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message