User Profile

Collapse

Profile Sidebar

Collapse
husoski
husoski
Last Activity: Nov 26 '18, 07:04 PM
Joined: Feb 27 '17
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • husoski
    replied to Faster search algorithm for lists
    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.
    See more | Go to post

    Leave a comment:


  • husoski
    replied to Faster search algorithm for lists
    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
    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
    If you are just making a reduced list, then you can do that without any explicit looping:

    ...
    See more | Go to post

    Leave a comment:


  • husoski
    replied to SyntaxError: Expected Indented Block
    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...
    See more | Go to post
    Last edited by husoski; Jun 15 '18, 10:51 PM. Reason: Add remark about <insert> tags in question.

    Leave a comment:


  • husoski
    replied to wheel algo
    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...
    See more | Go to post
    Last edited by husoski; Feb 27 '17, 02:54 PM. Reason: spelling error

    Leave a comment:

No activity results to display
Show More
Working...