X Tutup
Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: AllenDowney/ThinkPython2
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: DavidVFitzGerald/ThinkPython2
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Checking mergeability… Don’t worry, you can still create the pull request.
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on Oct 6, 2020

  1. Update rotate_pairs.py

    The current solution does not check for all rotated words, due to the stop argument of the range being 14 instead of 26 in the rotate_pairs function. For example, the word "act" should print out "act 24 yar", but currently does not print out anything.
    
    As the current solution uses a somewhat brute force approach, my suggested solution uses a different approach, where each word is rotated only once. It also makes use of a dictionary to store the rotate pairs, by using the setdefault method covered in Exercise 11.2.
    
    This suggested solution also directly addresses the specification of the exercise description ("Write a program that reads a wordlist and finds all the rotate pairs."). Only the word_list needs to be provided as argument, and a list containing lists with all rotate pairs is returned. Each word is thus contained only once in the returned list of lists.
    
    Since the suggested approach does not need to check for the presence of a word in the list of words, the words can be provided simply as a list instead of a dict.
    DavidVFitzGerald authored Oct 6, 2020
    Configuration menu
    Copy the full SHA
    a88192a View commit details
    Browse the repository at this point in the history
  2. Merge pull request #1 from DavidVFitzGerald/rotate_pairs

    Update rotate_pairs.py
    DavidVFitzGerald authored Oct 6, 2020
    Configuration menu
    Copy the full SHA
    f04a095 View commit details
    Browse the repository at this point in the history
Loading
X Tutup