5 ms·
The described issue is even simpler in shell scripting: cat file1.txt file2.txt | tr A-Z a-z | sort | uniq > whitelist.txt Does this mean people aren't goin
by eridius 12y ago
The described issue is even simpler in shell scripting:
cat file1.txt file2.txt | tr A-Z a-z | sort | uniq > whitelist.txt
Does this mean people aren't going to move from shell scripting to other languages? No, it just means the task is particularly suited to scripting like this, and Python has affordances for scripting.
- mattikus 12y agoIt can actually be even simpler: sort -u file1.txt file2.txt | tr A-Z a-z > whitelist.txt
- eridius 12y agoYou need the -f flag to sort as well to ignore case during the sorting. I don't know how portable the flags to sort are though which is why I didn't bother using them.
- vezzy-fnord 12y agoThis article is evidence that more people need to invest some time in learning shell scripting.
- moe 12y agoYour solution doesn't do the same thing, though. His code doesn't sort.
- mattikus 12y agoSure it does: https://gist.github.com/brettcannon/82c4fe68bac30f4ed653#file-gistfile1-py-L11 https://gist.github.com/brettcannon/82c4fe68bac30f4ed653#fil...
- moe 12y agoSorry, you are right, I missed that. Arguably your solution is still different because you sort the input instead of the output, but that's unlikely to matter here.
- eridius 12y agoThe only difference is I sort before uniquing, but the python code uniques before sorting. But the result is identical (and in shell scripting, you can't unique without sorting first). Although FWIW I just checked and the `sort` tool actually has a flag for uniquing during the sort. I don't know if that's portable though.
- moe 12y agoYes. Pedantically speaking his solution may be faster for the pathological case of the input consisting almost entirely of duplicates.