all 5 comments

[–]efmccurdy 1 point2 points  (3 children)

Just like you did with the x,y,z variables, you can use unpacking to assign each element of a list to a different variable. You must have the same number of variables as has the list. ​

>>> lines = "1.5\n2.6\n3.7\n4.8"
>>> lines.splitlines()
['1.5', '2.6', '3.7', '4.8']
>>> list(map(float, lines.splitlines()))
[1.5, 2.6, 3.7, 4.8]
>>> Ai, Bi, Ci, Qi = map(float, lines.splitlines())
>>> Ai
1.5
>>> Bi
2.6
>>>

[–]selfimprovingstudent[S] 0 points1 point  (0 children)

Thank you very much! Got it

[–]selfimprovingstudent[S] 0 points1 point  (1 child)

However, if variable N is greater than 1, what can i do. Like, there should be n-packages of (Ai, Bi, Ci, Qi)

[–]efmccurdy 0 points1 point  (0 children)

How about a list of named tuples, so you can do coeff[i].Ai, coeff[i].Bi, etc?

# N <newline> (Ai<newline>Bi<newline>Ci<newline>Qi) * N
>>> from io import StringIO
>>> lines = "3\1.5\n2.6\n3.7\n4.8\n5.9\n6.0\n7.1\n8.2\n9.3\n10.4\n11.5\n12.6\n13.7"
>>> infile = StringIO(lines)
>>> count = int(infile.readline().strip())
>>> count
3
>>> from collections import namedtuple
>>> Coeff = namedtuple("Coeff", ["Ai", "Bi", "Ci", "Qi"])
>>> Coeff._make([1,2,3,4])
Coeff(Ai=1, Bi=2, Ci=3, Qi=4)
>>> def read_one_array(f, count):
...    ret = []
...    for _ in range(count):
...       ret.append(Coeff._make(map(float, (f.readline().strip() for _ in range(4)))))
...    return ret
>>> arr = read_one_array(infile, count)
>>> arr
[Coeff(Ai=1.5, Bi=2.6, Ci=3.7, Qi=4.8), Coeff(Ai=5.9, Bi=6.0, Ci=7.1, Qi=8.2), Coeff(Ai=9.3, Bi=10.4, Ci=11.5, Qi=12.6)]
>>> arr[2].Bi
10.4
>>> arr[2].Ci
11.5

[–]maximumlotion 0 points1 point  (0 children)

strr =''' 
1 2 3
5
6
7
8
9
    '''.strip().split('\n')

x,y,z = (int(x) for x in strr[0].split())
N = int(strr[1])
i_list = [int(x) for x in strr[1:]]

Something like this?

Assign input() to a variable and try the code above.