How to parse an item in a list containing two floats and omit its parentheses in Python -
How to parse an item in a list containing two floats and omit its parentheses in Python -
this question has reply here:
unpacking function argument 2 answersso have list containing floats stored so:
points = [(0.06 , -4.00), (3.76, 0.02), (7.53, 0.09), (26.28, 1.15)]
so index[0] == (0.06, -4.00)
and pass them 1 1 function accepts parameters in format
point(x,y)
so @ first thought had solution with
for item in points: p = point(item)
i realised providing function with
point((0.06, -4.00))
which leaves function wanting 1 more parameter, seeing thinks 'x' variable. have seen string stripping, can't seem convert indices of points float after done stripping. think may due comma interfering.
some help or hints appreciated!
you can do:
for x, y in points: p = point(x, y)
or this:
for item in points: p = point(*item)
python list
Comments
Post a Comment