User Profile
Collapse
-
Searching a set is much faster than searching lists--even with the sublists you describe. It's a hash table search, and even if the key-hashing algorithm is a horrible match for the actual key distribution (nearly all "words" happen to hash to the same number, modulo the table size) then that worst-case performance is a sequential list search. Heads anytime you win; tails 30 times in a row you lose a little. -
It's much faster to search a set than a list. Since that list doesn't seem to change during the program run, simply use
If you are just making a reduced list, then you can do that without any explicit looping:Code:common_words = set(list_2) # after building list_2 from the file ... for word in list_1: if word in common_words: ...do the deletion
...Leave a comment:
-
You have begun a multi-line string literal for your docstring (starting with ''') but left out the closing '''. At the end of line 9, add that ''', or insert a line afterward consisting of just the ''' and nothing else. (My preference is to indent it 4 spaces to line up with the text above, but that's optional.)
I can't tell if there are other problems, since the code hasn't pasted correctly. Those "<insert>" tokens...Leave a comment:
-
I assume you meant "aebdc@" in your odd example. If so, then you can repeatedly remove the first and last characters from the input string, adding them to the output string in that order, until the length of the remaining string is less than 2.
Then, if there's a character remaining at the end (length is 1, not 0) then append it to the end of your output string, followed by a '@'.
It's been 15+ years since I've...Leave a comment:
No activity results to display
Show More
Leave a comment: