i want do edit a list in a python def function and get as return a new function. In the function the list should be sorted and some of the list-items should be replaced. The return should be a new list! Thx for help in advance..
i have a list1 = [a, d, b] the d should be replaced with a c and the list should be sorted. the new list should be [a, b, c]
>Solution :
Assuming that your letters start at the first letter and are in alphabetical order, this should work:
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
def Correct(l):
l.sort()
i = letters.index(l[0])
return letters[i:min(len(letters), i+len(l))]
And to try it out:
test = ['a', 'd', 'b']
Correct(test)
Which gives:
['a', 'b', 'c']