Skip to main content
11 events
when toggle format what by license comment
Apr 30, 2014 at 8:31 comment added 200_success Just say NO to global variables. My solution has none.
Apr 30, 2014 at 7:54 comment added ATT Thank you! So how do I manipulate global variables within recursion without stating them as global in the recursion?
Apr 29, 2014 at 12:18 comment added Michael Urman To expand on 200_success's point about commented out print statements, I would suggest replacing them with assert statements, unit tests, trips through pdb or another debugger, or removing them all together. Commented out code almost never belongs in a finished product.
Apr 28, 2014 at 6:54 comment added 200_success Try following the online book Composing Programs. If you're used to languages like C, then Section 1.6 (Higher-Order Functions) will blow your mind.
Apr 28, 2014 at 6:44 history edited 200_success CC BY-SA 3.0
Made more Pythonic, incorporating suggestions from @codesparkle
Apr 28, 2014 at 6:20 vote accept ATT
Apr 28, 2014 at 6:20 vote accept ATT
Apr 28, 2014 at 6:20
Apr 28, 2014 at 6:08 comment added ATT Thank you so much! This has been more than educational. As @Veedrac rightfully pointed about I am indeed lacking experience with real code (a student with only competitive programming experience under my belt). As you pointed out, my code looks like C code because I only started coding in Python recently. Besides what is already recommended by Veedrac, are there any resources you would recommend me to study to develop more abstract, Pythonic thinking?
Apr 28, 2014 at 4:33 comment added Adam Good review! {word: positions(text, word) for word in words} would be a dictionary-comprehension alternative to dict(...). The logic for finding start and end, though simple, is duplicated and could be extracted: start, end = find_bounds(combo) instead of having the nested span function.
Apr 28, 2014 at 4:14 history edited 200_success CC BY-SA 3.0
Modified handling when a search word is not found
Apr 28, 2014 at 4:09 history answered 200_success CC BY-SA 3.0