Jul-24-2018, 07:29 PM
I have two lists:
node=['v', 'r', 'r', 'v', 'r', 'r', 'r', 'r', 'v', 'v', 'r', 'v', 'v', 'v', 'v', 'v', 'v', 'v', 'v', 'v']
percent=[5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0, 55.0, 60.0, 65.0, 70.0, 75.0, 80.0, 85.0, 90.0, 95.0, 100.0]
I want to assign points to each node based on whether it is "v" or "r" and the relative position on a percent scale based on the "percent" list as follows;
for "v",
position 0-25=0,
position 26-50=2,
position 51-75=5,
position 76-100=10
for "r";
position 0-25=10,
position 26-50=5,
position 51-75=2,
position 76-100=1
I would like to end up with a new list that looks like this:
points=[0,10,0,10,5,5,5,2,2,2,5,5,5,5,10,10,10,10,10]
My code to attempt this is as follows:
node=['v', 'r', 'r', 'v', 'r', 'r', 'r', 'r', 'v', 'v', 'r', 'v', 'v', 'v', 'v', 'v', 'v', 'v', 'v', 'v']
percent=[5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0, 55.0, 60.0, 65.0, 70.0, 75.0, 80.0, 85.0, 90.0, 95.0, 100.0]
I want to assign points to each node based on whether it is "v" or "r" and the relative position on a percent scale based on the "percent" list as follows;
for "v",
position 0-25=0,
position 26-50=2,
position 51-75=5,
position 76-100=10
for "r";
position 0-25=10,
position 26-50=5,
position 51-75=2,
position 76-100=1
I would like to end up with a new list that looks like this:
points=[0,10,0,10,5,5,5,2,2,2,5,5,5,5,10,10,10,10,10]
My code to attempt this is as follows:
node=['v', 'r', 'r', 'v', 'r', 'r', 'r', 'r', 'v', 'v', 'r', 'v', 'v', 'v', 'v', 'v', 'v', 'v', 'v', 'v'] percent=[5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0, 55.0, 60.0, 65.0, 70.0, 75.0, 80.0, 85.0, 90.0, 95.0, 100.0] points=[] for nod in node: for val in percent: if nod == "v" and val <= 25: point=0 points.append(point) elif nod == "v" and 25 < val < 51: point=2 points.append(point) elif nod == "v" and 50 < val < 71: point=5 points.append(point) elif nod == "v" and 70 < val < 101: point=10 points.append(point) elif nod == "r" and val <= 25: point=10 points.append(point) elif nod == "r" and 25 < val < 51: point=5 points.append(point) elif nod == "r" and 50 < val < 71: point=2 points.append(point) elif nod == "r" and 70 < val < 101: point=1 points.append(point) print(points)It seems there is something I am not getting right. Is there a better way to do this?