相关疑难解决方法(0)

'int'对象没有属性'__getitem__'

import math
import os


class collection:
    col = [[0 for col in range(5)] for row in range(6)]
    dist = [[0 for col in range(6)] for row in range(6)]
    filename = ""
    result = ""

    def __init__(self,arg1):
        self.filename = arg1

    def coll(self):

        for i in range(6):
            try:
                if(i==0):
                    f = open(self.filename,'r')
                elif(i==1):
                    f = open("chap1.txt",'r')
                elif(i==2):
                    f = open("chap2.txt",'r')
                elif(i==3):
                    f = open("chap3.txt",'r')
                elif(i==4):
                    f = open("chap4.txt",'r')
                elif(i==5):
                    f = open("chap5.txt",'r')

                for j in range(5):
                    self.result = f.readline()
                    self.col[i][j] = self.result …
Run Code Online (Sandbox Code Playgroud)

python runtime-error

34
推荐指数
2
解决办法
19万
查看次数

在Python中,如何在排序列表中找到第一个值大于阈值的索引?

在Python中,如何在排序列表中找到第一个值大于阈值的索引?

我可以想到几种方法(线性搜索,手写二分法,......),但我正在寻找一种干净,合理有效的方法.由于它可能是一个非常常见的问题,我相信经验丰富的SOers可以提供帮助!

谢谢!

python algorithm search bisection

28
推荐指数
1
解决办法
2万
查看次数

用于查找重复项的Python方法

有没有办法找到列表是否包含重复项.例如:

list1 = [1,2,3,4,5]
list2 = [1,1,2,3,4,5]

list1.*method* = False # no duplicates
list2.*method* = True # contains duplicates
Run Code Online (Sandbox Code Playgroud)

python

2
推荐指数
1
解决办法
329
查看次数

标签 统计

python ×3

algorithm ×1

bisection ×1

runtime-error ×1

search ×1