# Aligning two lists of different datatype

I’m having trouble with trying to align lists together correctly with one holding an int datatype while the other is of strings. I’ve been practicing on iterating through a list comprised of college names, while the other list is of total in-state cost. I found out that when printing the list of college names it’s all in alphabetical order.

However, the total in-state costs don’t align with the appropriate college names. For example, Augustana college, which is first on the names list, has an incorrect tuition cost. So, Augustana has an index of 0 in names but the correct price has an index of 12 in the total cost list. Here’s a piece of code I did

``````costs=[cost for cost,group in colleges.groupby('Total Cost In-State')]
costs=[int(i) for i in costs]
print(costs)
``````

output will be:[15162, 19938, 22200, 23273, 27702, 29117, 29758, 31990, 37010, 37994, 45644, 50006, 53707, 65386]

Compare this to the picture I attached.
As seen, the order of the two list are non-existent and need help.

Hi.

I hope I understand your question!

have you tried to use the “zip-function”?

Example:

``````def test():

l1 = ['a', 'b', 'c', 'd']
l2 = [11, 2, 5, 1]

result = [x[1] for x in zip(l1, l2)]

return result
``````

test() ----> [11, 2, 5, 1] (sorted as expected)

If that is what you expect, you also can also define the function as follows:

``````def test(l1, l2):

result = [x[1] for x in zip(l1, l2)]

return result

``````

test( [‘a’, ‘b’, ‘c’, ‘d’], [11, 2, 5, 1]) -----> [11, 2, 5, 1]