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 answers

so 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

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -