✠
Size: a a a
✠
БГ
from functools import reduce
def to_binary(addr):
ints = (int(o) for o in addr.split("."))
n = reduce(lambda a, b: (a<<8)+b, ints)
return bin(n)[2:]
from functools import reduce
def to_binary(addr):
ints = (int(o) for o in addr.split("."))
n = reduce(lambda a, b: (a<<8)+b, ints)
return bin(n)[2:].zfill(32)
E
py3
from functools import reduce
def to_binary(addr):
ints = (int(o) for o in addr.split("."))
n = reduce(lambda a, b: (a<<8)+b, ints)
return bin(n)[2:]
print(to_binary("255.255.0.255"))
print(to_binary("192.168.0.1"))
11111111111111110000000011111111
11000000101010000000000000000001
K
БГ
from functools import reduce
def to_binary(addr):
ints = (int(o) for o in addr.split("."))
n = reduce(lambda a, b: (a<<8)+b, ints)
return bin(n)[2:].zfill(32)
py3
from functools import reduce
def to_binary(addr):
ints = (int(o) for o in addr.split("."))
n = reduce(lambda a, b: (a<<8)+b, ints)
return bin(n)[2:].zfill(32)
print(to_binary("0.0.0.0"))
print(to_binary("1.0.0.0"))
print(to_binary("0.0.0.1"))
00000000000000000000000000000000
00000001000000000000000000000000
00000000000000000000000000000001
R3
NK
E
E
БГ
py3
import functools
help(functools.reduce)
Help on built-in function reduce in module _functools:
reduce(...)
reduce(function, sequence[, initial]) -> value
Apply a function of two arguments cumulatively to the items of a sequence,
from left to right, so as to reduce the sequence to a single value.
For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates
((((1+2)+3)+4)+5). If initial is present, it is placed before the items
of the sequence in the calculation, and serves as a default when the
sequence is empty.
А
БГ
А
py3
import functools
help(functools.reduce)
Help on built-in function reduce in module _functools:
reduce(...)
reduce(function, sequence[, initial]) -> value
Apply a function of two arguments cumulatively to the items of a sequence,
from left to right, so as to reduce the sequence to a single value.
For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates
((((1+2)+3)+4)+5). If initial is present, it is placed before the items
of the sequence in the calculation, and serves as a default when the
sequence is empty.
K
E
E
NK
R3
БГ
NK