## Fix Python – What is the best way to get all the divisors of a number?

Here’s the very dumb way:
def divisorGenerator(n):
for i in xrange(1,n/2+1):
if n%i == 0: yield i
yield n

The result I’d like to get is similar to this one, but I’d like a smarter algorithm (this one it’s too much slow and dumb ðŸ™‚
I can find prime factors and their multiplicity fast enough.
I’ve an generator that generates facto….

## Fix Python – Why is Bubble Sort implementation looping forever?

In class we are doing sorting algorithms and, although I understand them fine when talking about them and writing pseudocode, I am having problems writing actual code for them.
This is my attempt in Python:
mylist = [12, 5, 13, 8, 9, 65]

unsorted = True

while unsorted:
for elemen….

## Fix Python – how to split an iterable in constant-size chunks [duplicate]

How do I split a list into equally-sized chunks?

Closed 5 months ago.

I am surprised I could not find a “batch” function that would take as input an iterable and return an….

## Fix Python – About Python’s built in sort() method

What algorithm is the built in sort() method in Python using? Is it possible to have a look at the code for that method?
….

## Fix Python – heapq with custom compare predicate

I am trying to build a heap with a custom sort predicate. Since the values going into it are of “user-defined” type, I cannot modify their built-in comparison predicate.
Is there a way to do something like:
h = heapq.heapify([…], key=my_lt_pred)
h = heapq.heappush(h, key=my_lt_pred)

Or even better, I could wrap the heapq functions in my own con….

## Fix Python – Checking if all elements in a list are unique

What is the best way (best as in the conventional way) of checking whether all elements in a list are unique?
My current approach using a Counter is:
>>> x = [1, 1, 1, 2, 3, 4, 5, 6, 2]
>>> counter = Counter(x)
>>> for values in counter.itervalues():
if values > 1:
# do something

Can I do better?
….

## Fix Python – Given a string of a million numbers, return all repeating 3 digit numbers

I had an interview with a hedge fund company in New York a few months ago and unfortunately, I did not get the internship offer as a data/software engineer. (They also asked the solution to be in Python.)
I pretty much screwed up on the first interview problem…

Question: Given a string of a million numbers (Pi for example), write
a function/p….

## Fix Python – How to trace the path in a Breadth-First Search?

How do you trace the path of a Breadth-First Search, such that in the following example:

If searching for key 11, return the shortest list connecting 1 to 11.
[1, 4, 7, 11]

….

## Fix Python – How to split text without spaces into list of words

Input: “tableapplechairtablecupboard…” many words
What would be an efficient algorithm to split such text to the list of words and get:
Output: [“table”, “apple”, “chair”, “table”, [“cupboard”, [“cup”, “board”]], …]
First thing that cames to mind is to go through all possible words (starting with first letter) and find the longest word pos….

## Fix Python – How to check whether two lists are circularly identical in Python

For instance, I have lists:
a[0] = [1, 1, 1, 0, 0]
a[1] = [1, 1, 0, 0, 1]
a[2] = [0, 1, 1, 1, 0]
# and so on

They seem to be different, but if it is supposed that the start and the end are connected, then they are circularly identical.
The problem is, each list which I have has a length of 55 and contains only three ones and 52 zeros in it. Witho….