Created
July 3, 2015 07:47
-
-
Save diegoceccarelli/c82388b865a5796b56fd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typefun=( | |
("string",str), | |
("int",int), | |
("float",float) | |
) | |
def get_parser(pattern, separator=','): | |
names, types = zip(*(map(lambda x: x.split(":"), pattern.split(",")))) | |
return lambda csv: dict(zip(names, map(lambda x: x[0](x[1]),zip(map(lambda x: dict(typefun)[x],types),csv.split(separator))))) | |
pattern="name:string,surname:string,age:int,height:float" | |
p = get_parser(pattern) | |
print p("diego,ceccarelli,31,74") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment