Skip to content

Commit

Permalink
set func faster and use nosec for bandit because of not security risk…
Browse files Browse the repository at this point in the history
… here
  • Loading branch information
Niccolum committed Sep 1, 2019
1 parent e6fc340 commit 556c7d1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions knapsack_problem/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ def _create_knapsack(weight_limit: int) -> Knapsack:
return Knapsack(tuple(items), weight_limit)


def _get_random_words(limit=None):
def _get_random_words(limit: int):
word_url = "http://svnweb.freebsd.org/csrg/share/dict/words?view=co&content-type=text/plain"
response = urllib.request.urlopen(word_url)
long_txt = response.read().decode()
words = long_txt.splitlines()[:limit]
with urllib.request.urlopen(word_url) as response: # nosec because of hardlink
lines = itertools.islice(response, limit)
words = [line.decode().rstrip() for line in lines]
random.shuffle(words)
while words:
yield words.pop()

0 comments on commit 556c7d1

Please sign in to comment.