0
lst = [1,2,3,4,5,6]
ste = {1,2,3,4,5,6}    
test = dict(zip(lst,ste))
print(test)

i don't want a result like this :

{1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6}

i need a result like this :

{6: 1, 5: 2, 4: 3, 3: 4, 2: 5, 1: 6}

How can i reverse a list and combine it with a set using zip function ?

2 Answers2

0

All you would need to do is reverse one of the two iterables, and since sets aren't indexable you are stuck with reversing the list. You also need to make sure that the first parameter of the zip function is the descending iterable in order to make sure that the first key in the dict is the largest number.

test = {i:j for i,j in zip(lst[::-1], ste)}

or

test = dict(zip(lst[::-1],ste))
Alexander
  • 16,091
  • 5
  • 13
  • 29
0
lst = [1,2,3,4,5,6]
lst = list(reversed(lst))
ste = {1,2,3,4,5,6}    
test = dict(zip(lst,ste))
print(test)
iambdot
  • 887
  • 2
  • 10
  • 28