Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.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
For loop 如何计算列表中的运行次数? def运行计数器(): #list1=生成整数列表(整数、低量程、高量程) 列表1=[6,12,9,10,1,2,3,4] 运行=0 对于范围内的i(len(列表1)-2): 而idef运行计数器(L): def run_counter(): #list1 = generate_integer_list(num_int, low_range, high_range) list1 = [6, 12, 9, 10, 1, 2, 3, 4] run = 0 for i in range(len(list1) - 2): while i < len(list1) - 1 and list1[i] == list1[i+1] - 1: run = i + 1 i += 1 return run, i - run+1 ... 答案=[] ... 开始=0 ... 结束=1 ... 当末端>L=[6,12,9,10,1,2,3,4] >>>运行计数器(L) [2, 2, 4] t我将使用函数中的注释生成列表,现在我正在使用预定义列表进行测试。 >>> def runCounter(L): ... answer = [] ... start = 0 ... end = 1 ... while end < len(L): ... if L[end] < L[end-1]: ... answer.append(end-start) ... start, end = end, end+1 ... end += 1 ... answer.append(end-start) ... return answer ... >>> L = [6, 12, 9, 10, 1, 2, 3, 4] >>> runCounter(L) [2, 2, 4]_For Loop_Python 3.x_While Loop_Nested - Fatal编程技术网

For loop 如何计算列表中的运行次数? def运行计数器(): #list1=生成整数列表(整数、低量程、高量程) 列表1=[6,12,9,10,1,2,3,4] 运行=0 对于范围内的i(len(列表1)-2): 而idef运行计数器(L): def run_counter(): #list1 = generate_integer_list(num_int, low_range, high_range) list1 = [6, 12, 9, 10, 1, 2, 3, 4] run = 0 for i in range(len(list1) - 2): while i < len(list1) - 1 and list1[i] == list1[i+1] - 1: run = i + 1 i += 1 return run, i - run+1 ... 答案=[] ... 开始=0 ... 结束=1 ... 当末端>L=[6,12,9,10,1,2,3,4] >>>运行计数器(L) [2, 2, 4] t我将使用函数中的注释生成列表,现在我正在使用预定义列表进行测试。 >>> def runCounter(L): ... answer = [] ... start = 0 ... end = 1 ... while end < len(L): ... if L[end] < L[end-1]: ... answer.append(end-start) ... start, end = end, end+1 ... end += 1 ... answer.append(end-start) ... return answer ... >>> L = [6, 12, 9, 10, 1, 2, 3, 4] >>> runCounter(L) [2, 2, 4]

For loop 如何计算列表中的运行次数? def运行计数器(): #list1=生成整数列表(整数、低量程、高量程) 列表1=[6,12,9,10,1,2,3,4] 运行=0 对于范围内的i(len(列表1)-2): 而idef运行计数器(L): def run_counter(): #list1 = generate_integer_list(num_int, low_range, high_range) list1 = [6, 12, 9, 10, 1, 2, 3, 4] run = 0 for i in range(len(list1) - 2): while i < len(list1) - 1 and list1[i] == list1[i+1] - 1: run = i + 1 i += 1 return run, i - run+1 ... 答案=[] ... 开始=0 ... 结束=1 ... 当末端>L=[6,12,9,10,1,2,3,4] >>>运行计数器(L) [2, 2, 4] t我将使用函数中的注释生成列表,现在我正在使用预定义列表进行测试。 >>> def runCounter(L): ... answer = [] ... start = 0 ... end = 1 ... while end < len(L): ... if L[end] < L[end-1]: ... answer.append(end-start) ... start, end = end, end+1 ... end += 1 ... answer.append(end-start) ... return answer ... >>> L = [6, 12, 9, 10, 1, 2, 3, 4] >>> runCounter(L) [2, 2, 4],for-loop,python-3.x,while-loop,nested,For Loop,Python 3.x,While Loop,Nested,运行是一个连续的数字顺序:1、2、3、4。10、11、12等,供不知道的人使用 我试图创建一个函数,返回它在列表中遇到的第一次运行的长度,以及运行开始的索引 我上面的代码并不能真正起作用。它应该返回,长度为2,从2开始,但返回长度为7,从1开始。有什么想法吗?>def运行计数器(L): def run_counter(): #list1 = generate_integer_list(num_int, low_range, high_range) list1 = [6, 12,

运行是一个连续的数字顺序:1、2、3、4。10、11、12等,供不知道的人使用

我试图创建一个函数,返回它在列表中遇到的第一次运行的长度,以及运行开始的索引

我上面的代码并不能真正起作用。它应该返回,长度为2,从2开始,但返回长度为7,从1开始。有什么想法吗?

>def运行计数器(L):
def run_counter():
    #list1 = generate_integer_list(num_int, low_range, high_range)
    list1 = [6, 12, 9, 10, 1, 2, 3, 4]
    run = 0
    for i in range(len(list1) - 2):
        while i < len(list1) - 1 and list1[i] == list1[i+1] - 1:
            run = i + 1
            i += 1
    return run, i - run+1
... 答案=[] ... 开始=0 ... 结束=1 ... 当末端<长度(L): ... 如果L[end]>>L=[6,12,9,10,1,2,3,4] >>>运行计数器(L) [2, 2, 4]
t我将使用函数中的注释生成列表,现在我正在使用预定义列表进行测试。
>>> def runCounter(L):
...   answer = []
...   start = 0
...   end = 1
...   while end < len(L):
...     if L[end] < L[end-1]:
...       answer.append(end-start)
...       start, end = end, end+1
...     end += 1
...   answer.append(end-start)
...   return answer
... 
>>> L = [6, 12, 9, 10, 1, 2, 3, 4]
>>> runCounter(L)
[2, 2, 4]