Changed hard tabs to soft tabs(2 spaces)
This commit is contained in:
@ -8,12 +8,12 @@ Sorts one list based on given indices in another list and returns the sorted lis
|
||||
Use list comprehension to get values after using `zip` and `sorted` function based on given `key` with lambda function that returns the index.
|
||||
|
||||
```py
|
||||
def sort_list_based_on_another_list(to_sort, index_list):
|
||||
return [val for i, val in sorted(zip(index_list, to_sort), key = lambda x: x[0])]
|
||||
def sort_list_based_on_another_list(list_to_sort, index_list):
|
||||
return [val for i, val in sorted(zip(index_list, list_to_sort), key = lambda x: x[0])]
|
||||
```
|
||||
|
||||
```py
|
||||
a = ['eggs', 'bread', 'oranges', 'jam', 'apples', 'milk']
|
||||
b = [3, 2, 6, 4, 1, 5]
|
||||
sort_list_based_on_another_list(a, b) # ['apples', 'bread', 'eggs', 'jam', 'milk', 'oranges']
|
||||
```
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user