Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 71ce1ce

Browse files
author
Amogh Singhal
authored
Create permutations.py
1 parent 18c078c commit 71ce1ce

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

‎permutations.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
def permutations(word):
2+
if len(word) == 1:
3+
return [word]
4+
else:
5+
result = []
6+
for p in permutations(word[1:]):
7+
print(p, word[1:])
8+
print("\n")
9+
for i in range(len(word)):
10+
print(i, "1"+p[:i], "2"+word[0:1], "3"+p[i:])
11+
current_p = p[:i] + word[0:1] + p[i:]
12+
result.append(current_p)
13+
14+
return result
15+
16+
given_input = "bc"
17+
print(permutations(given_input))

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /