How to understand the functional programming code for converting IP string to a number?
Posted
by
zfz
on Stack Overflow
See other posts from Stack Overflow
or by zfz
Published on 2012-10-31T10:51:49Z
Indexed on
2012/10/31
11:00 UTC
Read the original article
Hit count: 159
In a python discusion, I saw a way to convert IP string to a integer in functional progamming way. Here is the Link .
The function is implemented in a single line.
def ipnumber(ip):
return reduce(lambda sum, chunk: sum <<8 | chunk, map(int, ip.split(".")))
However, I have few ideas of funcional programming. Could anybody explain the function in detail? I've some knowledg of "map" and "reduce". But I don't konw what "|" and "chunk" mean here?
Thanks.
© Stack Overflow or respective owner