Hacker News new | past | comments | ask | show | jobs | submit login

One single productivity python I'd like to share here is to use 'string foo'.partition(' ') instead of splitting. The reason is the edge cases are better handled with partition: you always get a 3-tuple, no matter what. No need to precheck that the split is here, or to postcheck the length of the splitted list.



On the other hand, .split() with no argument splits on any amount of whitespace (\s+, as a regex). That's often quite a useful edge case to have handled for you. You can also do .split(c, 1) to limit it to a single split. It could still split 0 times, though - it just depends which edge cases you want to handle.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: