New answers tagged

1 vote

Pascal's triangle solution in Python code

Use functions. You have a review with some useful advice, and its best advice is that you organize your programs around functions. Here I'll extend that idea. Functions should be focused. If we take a ...
user avatar
  • 9,475
1 vote

Pascal's triangle solution in Python code

PEP 8 The Style Guide for Python Code has many recommendations that all Python programs should follow. These include: snake_case for variable and function names, ...
user avatar
  • 30.4k
1 vote
Accepted

Subset Product Algorithm

Reasons to put code in functions (and classes): Code on module level is evaluated right away: I can't try it out using copy&paste if there is an input() ...
user avatar
  • 4,283
6 votes
Accepted

Find non-overlapping pairs of elements in a list whose difference is less than some given threshold

Your code is doing far too much work. If we sort the list before we start, then we need only compare adjacent elements as candidates. Whenever we find a pair that satisfies our predicate, then add it ...
user avatar
  • 57.6k
6 votes

Find non-overlapping pairs of elements in a list whose difference is less than some given threshold

You need pairs, not partitions. Your current implementation does a lot of unnecessary work. It looks like you are generating all possible partitions of the input collection and then rejecting the ones ...
user avatar
  • 9,475

Top 50 recent answers are included