小编Man*_*dar的帖子

如何在python中获取锯齿状数组的长度

我试图获取我的列表中从SQLAlchemy命令更新的项目总数,它是一个像这样的锯齿状数组..

list = [['linux'], ['ML'], ['linux', 'ML', 'Data Science', 'GIT'],['linux', 'Data Science', 'GIT'], ['GIT'], ['ML', 'GIT'], ['linux'], ['linux'], ['linux'], ['Data Science']]
length = len(list)
Run Code Online (Sandbox Code Playgroud)

我得到的输出为:10

我如何获得长度:16?这是列表中的项目总数吗?

python arrays list

5
推荐指数
1
解决办法
390
查看次数

如何降低给定 python 代码的时间复杂度?

我有这个 python 程序,它计算给定数字的“自由平方数”。我面临着时间复杂度的问题,即我在在线编译器中收到“超出时间限制”的错误。

number = int(input())
factors = []
perfectSquares = []
count = 0
total_len = 0

# Find All the Factors of the given number
for i in range(1, number):
if number%i == 0:
    factors.append(i)

# Find total number of factors        
total_len = len(factors)

for items in factors:
    for i in range(1,total_len):
  # Eleminate perfect square numbers
    if items == i * i:
        if items == 1:
            factors.remove(items)
            count += 1
        else:
            perfectSquares.append(items)
            factors.remove(items)
            count += 1

# …
Run Code Online (Sandbox Code Playgroud)

time-complexity python-3.x

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

标签 统计

arrays ×1

list ×1

python ×1

python-3.x ×1

time-complexity ×1