Need tips for speeding up python code - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: Need tips for speeding up python code (/thread-10622.html) |
Need tips for speeding up python code - iineo - May-28-2018 from numpy import array, bitwise_or from itertools import combinations, chain n,k=map(int,input().split()) arr=list(map(int,input().split())) tup=map(list,chain.from_iterable(map(lambda x:combinations(arr,x),range(1,k+1)))) ans=map(lambda x:bitwise_or.reduce(array(x,dtype='int')),tup) print(len(set(ans)))n is the number of elements in set the code makes subsets of size <= k and performs bitwise or on each subset and prints the number of unique elements formed RE: Need tips for speeding up python code - micseydel - May-29-2018 Do you know what part is slow? If not, you might want to try profiling it. |