Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么这段代码显示内存错误?可能while循环有问题_Python_Python 3.x_While Loop - Fatal编程技术网

Python 为什么这段代码显示内存错误?可能while循环有问题

Python 为什么这段代码显示内存错误?可能while循环有问题,python,python-3.x,while-loop,Python,Python 3.x,While Loop,此代码用于查找字符串的子集,该子集具有唯一字符。 将字符串的k部分设为t,然后打印这些部分,同时不在字符串中包含相同的字符 def merge_the_tools(string, k): l = len(string) start = 0 t = [] ans = [] while True: put='' for i in range(start,start

此代码用于查找字符串的子集,该子集具有唯一字符。 将字符串的k部分设为t,然后打印这些部分,同时不在字符串中包含相同的字符

    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)

我认为while循环有一个问题,我找不到。

您的需求不清楚,我将以我对您的代码的理解作出回应

您需要更改start或k的值,因为在这里您将被困在start=2和k=2中

换线

Start = k


它应该工作并无限期地停止运行。

您不更新k?
k==2
start=0
l==8
-如果0+2==8,您将中断
,并且从不增加
start
(0)或
k
(2)…-使用
print(…)
调试您的代码并阅读ok我现在就知道了,谢谢,我确实开始了=开始+k,并且工作正常
start += k