Q:

Splitting two lists and assigning data from one list to values in the other

and thank you in advance for the help. My problem concerns methods in Python and is as follows.
I have two lists. One list, x, is made up of rows that contain 2 values, x1 and x2, each. The second list, data is made up of rows that contain 3 values, x0, t, and r, each. I split each row accordingly:
for datum in data:
    x0, t, r = data.split()

for item in x:
    x1, x2 = x.split()

Values of x1 and x2 may be found within values of x0. If x1 corresponds to a value of x0, I would like to assign to x1 the values of t and r that also correspond to that x0. I would like to perform this for each x2 as well. The end result will be to make some calculation for each pair of x1 and x2 values using the values t and r.
For example: Say we have two lines from data (x0,t,r):
311 0 2
202 5 13
And we have one line from x (x1,x2):
311 202
In the end I'd like to assign the values 0 and 2 to x1 and 5 and 13 to x2 so that I can make an arbitrary calculation such as y=r1-r2+t1*t2, where r1 is the r value assigned to x1, etc. Note that I would like to be able to calculate this for every row in x. 
Thanks again!

A:

Build a dictionary from data with the key x0:
dataDictionary = {}
for datum in data:
    x0, t, r = datum.split()
    dataDictionary[x0] = t, r

This allows you to look up values from data based on x0.
Now, when you loop through x, you can get those values and do your calculations:
for item in x:
    x1, x2 = item.split()
    t1, r1 = dataDictionary[x1]
    t2, r2 = dataDictionary[x2]
    y = r1 - r2 + t1 * t2
    print(y)

