我试图获取我的列表中从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 程序,它计算给定数字的“自由平方数”。我面临着时间复杂度的问题,即我在在线编译器中收到“超出时间限制”的错误。
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)