AChampion
• Member for 6 years, 4 months
• Last seen more than a month ago
• US (via U.K)

A simple algorithm that uses heapq. Construct heap with (-count, value) [Negative count provides the appropriate priority as heapq returns lowest first] Pop from heap if no previous element or ...

Using the roundrobin() recipe from itertools is already pythonic. The solve() method could be replaced with more use of itertools. In particular itertools.groupby() would do the same as your ...

Some comments on your code. Overall you are using a lot of unnecessary variables. another_word = " " sentence1 = " " new_list = [] another = " " You really don't need these variables declared ...

Why do you assume this code is limited to 10 vertices? This code comes from: http://www.geeksforgeeks.org/greedy-algorithms-set-2-kruskals-minimum-spanning-tree-mst/ But you have an error in use: g ...

A slightly more efficient dynamic programming approach means you only need O(n) space: def partitions(n): parts = [1]+[0]*n for t in range(1, n+1): for i, x in enumerate(range(t, n+1))...

Given even the naive solution finishes in ms, is this one test you care about optimising? It can be done in one line which would be in the order of the naive solution: max(reduce(mul, (int(a) for a ...

A couple of high-level comments: You have many places where you can pull things out of the conditionals to avoid repeating yourself (DRY principle) I would look to pass values into functions vs. ...

You can hugely reduce your __str__ using loops, e.g. using join() and a couple of generator expressions: def __str__(self): return '\n-----------\n'.join(' | |\n '+' | '.join(str(self.spaces[...

A couple of stylistic comments and python gotchas: If you are just starting out in Python I would look to use Py3 and if you can't use Py3, use some of the __future__ imports to ensure you are ...

Maximum subarray is pretty well known problem with a simple algorithm to solve in O(n). Directly from the link above: def max_subarray(A): max_ending_here = max_so_far = A[0] for x in A[1:]: ...