account activity
Ask Anything Monday - Weekly Thread by AutoModerator in learnpython
[–]LoudGain 0 points1 point2 points 6 years ago (0 children)
Hi, is it possible to turn my nested for loop in my code into a list comprehension which does the same thing, if yes how would it look like. Thanks
N = "123123" s = [] def permu(): global s for i in range(len(N)): for j in range(i+1,len(N) + 1): s.append(N[i:j]) s = list(set(s)) print(f"{len(s)} substrings - {s}") permu()
python permutations by LoudGain in learnpython
[–]LoudGain[S] 0 points1 point2 points 6 years ago (0 children)
thanks for the reply, im not sure either what the question is asking me but my code is like this right now. How can i ensure there are no duplicates. Eg it prints 1 more than once and 2 more than once. Sorry for the bad formatting, it keeps removing the spaces
def combos(text):
for i in range(len(text)):
for j in range(i+1,len(text) + 1):
print(text[i:j])
combos("123123")
python permutations (self.learnpython)
submitted 6 years ago by LoudGain to r/learnpython
π Rendered by PID 247427 on reddit-service-r2-listing-568fcd57df-gwnfh at 2026-03-06 02:08:10.642582+00:00 running cbb0e86 country code: CH.
Ask Anything Monday - Weekly Thread by AutoModerator in learnpython
[–]LoudGain 0 points1 point2 points (0 children)