Changed hard tabs to soft tabs(2 spaces)

This commit is contained in:
Sahith Kurapati
2020-06-19 17:27:35 +05:30
committed by GitHub
parent 48fc7ebf29
commit a1357e543d

View File

@ -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']
```
```