Skip to content

Commit e2b1321

Browse files
committed
changed
1 parent 1235309 commit e2b1321

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

list_permutation.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Learn Python together
2-
""" Given an array nums of distinct integers, return all the possible permutations. """
32

3+
""" Given an array nums of distinct integers, return all the possible permutations.
4+
"""
45
# Solution 1 using loop and recursive
56

67
def permute(nums):
@@ -9,10 +10,14 @@ def permute(nums):
910
result= [] # empty list
1011
# iteration through each item in the list
1112
for i in range(len(nums)):
12-
lis = nums[i] # giving value at index i in lis variable
13-
new_list = nums[:i]+nums[i+1:] # giving in new list all elemts of the list exclude lis
14-
for perm in permute(new_list): # recursive call function for creating permutation
15-
result.append([lis]+perm) # add variables to result
13+
# giving value at index i in lis variable
14+
lis = nums[i]
15+
# giving in new list all elemts of the list exclude lis
16+
new_list = nums[:i]+nums[i+1:]
17+
# recursive call function for creating permutation
18+
for perm in permute(new_list):
19+
# add variables to result
20+
result.append([lis]+perm)
1621
return result
1722

1823
#check

0 commit comments

Comments
 (0)