2 ms·
Just picking on one section. The Python: contactRecords = filter(lambda r: r[1] == "1", contactRecords) Versus the Ruby: contactRecords.reject! {|a| a[1]
by petercooper 17y ago
Just picking on one section. The Python:
contactRecords = filter(lambda r: r[1] == "1", contactRecords)
Versus the Ruby:
contactRecords.reject! {|a| a[1] != "1"}
Yet the author points out that not everyone will appreciate the blocks.. even though the Python variant is using much the same thing, just as an explicit lambda.
In what universe is the Python variant make readable? The variable name is repeated (not very OO like) and there's more syntactic salt and verbosity.
- jeremymcanally 17y agoI'm not sure we'd consider this good Python these days; Python had some ugly warts and quirks that got fixed in later versions.
- altano 17y agoWhat does the equivalent code in the latest version of Python look like?
- EliAndrewC 17y agocontactRecords = [r for r in contactRecords if r[1] == "1"]
- adw 17y agoAnd in reasonably idiomatic recent Python, the whole thing'd be: #!/usr/bin/env python import fileinput import csv EMAIL, CONTACTME, SKUTITLE = 17, 27, 34 tsl = csv.reader(fileinput.input(), dialect='excel-tab') for line in sorted([r[SKUTITLE], r[CONTACTME], r[EMAIL]] for r in tsl if r[CONTACTME] == "1"): print "\t".join(line) It's going to be good in any language though, isn't it?