Skip to content

Commit

Permalink
Use a generater rather than a list
Browse files Browse the repository at this point in the history
  • Loading branch information
suminb committed Apr 10, 2017
1 parent f83c57d commit 6c70a64
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions base62.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ def bytes_to_int(s, byteorder='big', signed=False):
try:
return int.from_bytes(s, byteorder, signed=signed)
except AttributeError:
# Python 2.x
# For Python 2.x
if byteorder != 'big' or signed:
raise NotImplementedError()

# NOTE: This won't work if a generator is given
n = len(s)
cs = list(bytearray(s))
ds = [x << (8 * (n - 1 - i)) for i, x in enumerate(cs)]
ds = (x << (8 * (n - 1 - i)) for i, x in enumerate(bytearray(s)))

return sum(ds)

Expand Down

0 comments on commit 6c70a64

Please sign in to comment.