The search algorithm for all divisors of the number
📁 function, List, Advanced Python Topics, example
Hi! While solving a problem on the network, an algorithm for finding all divisors of a number. That is, for eight it should output [1,2,4,8], not [2,2,2] - a list of divisors. I rewrote this algorithm from scratch, I ask "senior comrades" to tell me how to improve it. If you have time))
def divisors(n): from collections import Counter ls = get_ls(n) # for n = 1568 -> ls = [2, 2, 2, 2, 2, 7, 7] pairs = dict(Counter(ls)) # {2: 5, 7: 2} from itertools import p No answers yet.
Log in to leave an answer
Blogs