Simplify code by dropping support for legacy Python (#1143)

* Simplify code by dropping support for legacy Python

* sort() --> sorted()
This commit is contained in:
Christian Clauss
2019-08-19 15:37:49 +02:00
committed by GitHub
parent 32aa7ff081
commit 47a9ea2b0b
145 changed files with 367 additions and 976 deletions

View File

@ -14,12 +14,6 @@ It is possible to write five as a sum in exactly six different ways:
How many different ways can one hundred be written as a sum of at least two
positive integers?
"""
from __future__ import print_function
try:
xrange # Python 2
except NameError:
xrange = range # Python 3
def partition(m):
@ -43,12 +37,12 @@ def partition(m):
>>> partition(1)
0
"""
memo = [[0 for _ in xrange(m)] for _ in xrange(m + 1)]
for i in xrange(m + 1):
memo = [[0 for _ in range(m)] for _ in range(m + 1)]
for i in range(m + 1):
memo[i][0] = 1
for n in xrange(m + 1):
for k in xrange(1, m):
for n in range(m + 1):
for k in range(1, m):
memo[n][k] += memo[n][k - 1]
if n > k:
memo[n][k] += memo[n - k - 1][k]