Approach 2: By using Dictionary, list comprehension, lambda function
def sorting_of_element(list1, list2):
initializing blank dictionary
f_1 = {}
initializing blank list
final_list = []
Addition of two list in one dictionary
f_1 = {list1[i]: list2[i] for i in range(len(list2))}
sorting of dictionary based on value
f_lst = {k: v for k, v in sorted(f_1.items(), key=lambda item: item[1])}
Element addition in the list
for i in f_lst.keys():
final_list.append(i)
return final_list
list1 = ["a", "b", "c", "d", "e", "f", "g", "h", "i"]
list2 = [0, 1, 1, 0, 1, 2, 2, 0, 1]
list3 = sorting_of_element(list1, list2)
print(list3)
Output
['a', 'd', 'h', 'b', 'c', 'e', 'i', 'f', 'g']
In questa pagina del sito puoi guardare il video online Python Programming Approach 2: By using Dictionary, list comprehension, lambda function della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Tech Tips 04 novembre 2022, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 171 volte e gli è piaciuto 4 spettatori. Buona visione!