3 ms·
At least for the contrived example from the article, the solution isn't to break up the code, but to use denser code. Use a regex. Does anybody really think th
by gilch 4y ago
At least for the contrived example from the article, the solution isn't to break up the code, but to use denser code. Use a regex.
Does anybody really think that e.g. sregex[1] is better than just learning and using the regex language directly? Because that's where this kind of thinking leads.
[1]: https://github.com/jwiegley/emacs-release/blob/master/lisp/obsolete/sregex.el https://github.com/jwiegley/emacs-release/blob/master/lisp/o...
- cavisne 4y agoI think for any code thats meant to be read and maintained by someone else a regex is a bad idea. You are saving a few lines on the surface, but adding a potential backtracking bug in the future.
- toiletduck 4y agoI know it's not the point the author is trying to make, but I couldn't help get the feeling this example isn't good enough to carry the point. from stdlib: from urllib.parse import urlparse, parse_qsl url = 'https://www.example.com/some_pathsome_key=some_value&foo=bar' parsed_url = urlparse(url) values = [v for _, v in parse_qsl(parsed_url.query)] print(values) which I guess you could oneliner back to this.. [v for _, v in parse_qsl(urlparse(url).query]