小编Aut*_*tic的帖子

long double return和ctypes

我有一个返回a的交流功能long double.我想使用ctypes从python中调用这个函数,它主要起作用.设置so.func.restype = c_longdouble可以解决问题 - 除了python的float类型是c_double如此,如果返回的值大于double,但是在long double的范围内,python仍然将inf作为返回值.我是64位处理器,sizeof(long double)是16.

没有修改c代码的任何想法(例如使用十进制类或numpy)?

python ctypes

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

Python,巨大的迭代性能问题

我正在做3个单词的迭代,每个单词大约有500万个字符,我想找到20个字符的序列来识别每个单词.也就是说,我想在一个单词中找到长度为20的所有序列,这个序列对于该单词是唯一的.我的问题是我写的代码需要很长时间才能运行.我甚至没有完成一个单词来运行我的程序过夜.

下面的函数采用包含字典的列表,其中每个字典包含20个可能的单词,以及500万个单词之一的位置.

如果有人知道如何优化这个我会非常感激,我不知道如何继续......

这是我的代码示例:

def findUnique(list):
    # Takes a list with dictionaries and compairs each element in the dictionaries
    # with the others and puts all unique element in new dictionaries and finally
    # puts the new dictionaries in a list.
    # The result is a list with (in this case) 3 dictionaries containing all unique
    # sequences and their locations from each string.
    dicList=[]
    listlength=len(list)
    s=0
    valuelist=[]
    for i in list:
        j=i.values()
        valuelist.append(j)
    while s<listlength:
        currdic=list[s]
        dic={}
        for key …
Run Code Online (Sandbox Code Playgroud)

python iteration bioinformatics

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

递归地计算列表的长度

如果你有一个列表= [1,2,3,4,5]

如何在不使用len(list)的情况下以递归方式计算该列表的长度?

myarray = [1,2,3,4,5]

def mylist(myarray):
    if (myarray == []):
        print ("The list is empty")
        return 
    return 1 + ?
Run Code Online (Sandbox Code Playgroud)

不想使用len但每次在列表中存在值时只添加1.我该怎么办?

python recursion function

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

标签 统计

python ×3

bioinformatics ×1

ctypes ×1

function ×1

iteration ×1

recursion ×1