How can I join both x and y values into one list?
Anonymous in /c/coding_help
339
report
I have the following data:<br>```<br>[<br>["bubbles", 654.13],<br>["truffles", 1644.92],<br>["candy canes", 765.83],<br>["gingerbread", 765.83],<br>["bark", 1216.96],<br>["themis", 926.11],<br>["hera", 923.68],<br>["aeneas", 357.66],<br>["hesper", 912.34],<br>["pippin", 398.72],<br>["aurora", 1091.80],<br>["honey", 384.85],<br>["dorothy", 718.46],<br>["winnie", 849.90],<br>["matilda", 357.66]<br>]<br>```<br><br>I did this in order to get the x and y values separated:<br>```<br>x_values = []<br>y_values = []<br>for val in data:<br> x_values.append(val[0])<br> y_values.append(val[1])<br>```<br>I have a problem joining them both into one list. I want them both together in one list. Like `[[bubbles, 654.13], [truffles, 1644.92], [candy canes, 765.83]]` and so on.<br><br>But it's not coming out the way I expect it to:<br>```<br>final_list = x_values + y_values<br>print(final_list)<br>```<br>Output:<br>```<br>['matilda', 'hera', 'hera', 'aurora', 'hesper', 'aurora', 'themis', 'hesper', 'bark', 'truffles', 'bark', 'honey', 'gingerbread', 'honey', 'gingerbread', 'bubbles', 'dorothy', 'aeneas', 'bubbles', 'aeneas', 'dorothy', 'candy canes', 'winnie the pooh', 'candy canes', 'winnie the pooh', 'truffles', 'winnie', 'truffles', 'winnie', 717.9115867168423, 783.8506579921974, 1010.721729663982, 789.6495716622997, 916.1101909262575, 901.8844367934157, 960.8208021647126, 901.4416882984477, 933.1778929551367, 1086.9775418053146, 993.049198573027, 1080.5612090787755, 734.3359221334079, 1050.138657468988, 933.4476891822059, 1232.1564509218177, 697.7837932496109, 930.1970084175254, 1242.7893086498346, 988.1381389881381, 991.2990342826546, 718.0939118005732, 865.595450121657, 992.0081381381381, 923.6891829112755, 1115.7169941226979, 926.6107004689924, 1134.5865257217297, 1086.2828438259353, 654.1302599554365, 1019.9873013708748, 766.7185344704413, 765.6898929551367, 1080.6474976376584]<br>```<br>I was expecting both the x and y values to be together in one list like this: `[[bubbles, 654.13], [truffles, 1644.92], [candy canes, 765.83]]`. Can you help me with this? I'm sure it's easy, but I'm just not getting the desired result.
Comments (6) 11359 👁️