How to solve Python Memory Error ?. While loop does not stop running
Question:
this code is to find a subset of a string, which has unique characters.
make k parts of the string and t then print these parts while not includeing the same character in the string
def merge_the_tools(string, k):
l = len(string)
start = 0
t = []
ans = []
while True:
put=''
for i in range(start,start+k):
put += string[i]
start = k
t.append(put)
if start + k == l:
break
for i in t:
ss = set(i)
s = ''
for j in ss:
s += j
ans.append(s)
for i in s:
print(I)
merge_the_tools('AABBAACC',2)
I think there is a problem with ,while loop which I’m not able to find.
Answers:
Your need is not clear and I will respond with my understanding of your code.
you need to change the value of your start or k because here you will be stuck in start = 2 and k = 2.
Change the line
Start = k
by
start += k
it should work and stop running for infinite time.
this code is to find a subset of a string, which has unique characters.
make k parts of the string and t then print these parts while not includeing the same character in the string
def merge_the_tools(string, k):
l = len(string)
start = 0
t = []
ans = []
while True:
put=''
for i in range(start,start+k):
put += string[i]
start = k
t.append(put)
if start + k == l:
break
for i in t:
ss = set(i)
s = ''
for j in ss:
s += j
ans.append(s)
for i in s:
print(I)
merge_the_tools('AABBAACC',2)
I think there is a problem with ,while loop which I’m not able to find.
Your need is not clear and I will respond with my understanding of your code.
you need to change the value of your start or k because here you will be stuck in start = 2 and k = 2.
Change the line
Start = k
by
start += k
it should work and stop running for infinite time.