Need in python thank youSolutiondef permutationslst if lenls


Need in python, thank you.

Solution

def permutations(lst):
    if len(lst)==0 or len(lst)==1:
        return [lst]
    l = []
    for i in range(len(lst)):
        m = lst[i]
        rem_lst = lst[:i] + lst[i+1:]
        for p in permutations(rem_lst):
            l.append([m]+p)
    return l

print permutations([1, 2, 3, 4])

 Need in python, thank you.Solutiondef permutations(lst): if len(lst)==0 or len(lst)==1: return [lst] l = [] for i in range(len(lst)): m = lst[i] rem_lst = lst[

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site