arrays - Loop that skips the values it already done -
with code mange take take different possibilities, add them , put in data in arrays. problem duplicated data want skip. example:
first: name1, name2, total points of 2 , total price two. then: name2, name1, total points of 2 , total price two. which exact same result in diffrent order.
data list of 3 colums 50 lines ( name , price , point )
price = 0 points = 0 l1 = [] l2 = [] l3 = [] l4 = [] in range(0,18): i2 in range(0,18): points = data['points'][i]+data['points'][i2] price = data['price'][i]+data['price'][i2] if price < 10 , != i2: l1.append(points) l2.append(price) l3.append(data['name'][i]) l4.append(data['name'][i2]) print points , price, data['name'][i], data['name'][i2] print '_____' print ''
question: how solve problem?
change loop avoid going on every combination twice:
for in range(0,18): i2 in range(0,i): ...
i delay points = data['points'][i]+data['points'][i2]
calculation after if
case save little time.
and don't need initialize variables price = 0, points = 0
since redefined on every iteration anyway. python dynamic langue variable declarations unnecessary.
Comments
Post a Comment