Skip to content

Update rotate_pairs.py #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 6, 2020
Merged

Update rotate_pairs.py #1

merged 1 commit into from
Oct 6, 2020

Conversation

DavidVFitzGerald
Copy link
Owner

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.

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 DavidVFitzGerald merged commit f04a095 into master Oct 6, 2020
@DavidVFitzGerald DavidVFitzGerald deleted the rotate_pairs branch October 6, 2020 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant