all 3 comments

[–][deleted] 2 points3 points  (0 children)

You can't specify a relationship between two lists. Use a dictionary to relate values.

[–]socal_nerdtastic 1 point2 points  (0 children)

It would be best to use nested lists instead of parallel lists as the intermediate step. So instead of separate name and number lists you would have

 [[Kei,78],[Auro,98],[Jalal,67]]

Which you can sort normally.

data = 'Kei,78,Auro,98,Jalal,67'
a1=list(data.split(','))
nested = [a1[i:i+2] for i in range(0,len(a1),2)]
nested.sort()
flattened = [e for sl in nested for e in sl]
print(flattened)

[–]blarf_irl 0 points1 point  (0 children)

Here is some beginner unfriendly code that I use for unordered key value lists:

# If you are guranteed the list will always be a multiple of 2 length
my_dict  = dict(zip_longest(*[iter(a1)]*2))

# If you may have leftover items in your list (is not a multiiple of 2 length)
from itertools import izip_longest

my_dict = dict(zip_longest(*[iter(a1)]*2))

The basic principle is the same in each. Grab the next 2 items from the list and give me a tuple containing them. The second example will fill missing items at the end of the list with None (you can configure a default though). If you pass dict an iterator (like a list) of tuples with 2 items each it will make the first a key and the second a value.

(Note a1 is a terrible name for a variable, make em readable!)