Skip to content

Assignment 1#1

Open
dhamijap wants to merge 7 commits intomainfrom
assignment-1
Open

Assignment 1#1
dhamijap wants to merge 7 commits intomainfrom
assignment-1

Conversation

@dhamijap
Copy link
Copy Markdown
Owner

What changes are you trying to make? (e.g. Adding or removing code, refactoring existing code, adding reports)

Completion of Python assignment 1.

What did you learn from the changes you have made?

I originally made for loops to iterate through the word and append each character to a list. I did not think that was the most efficient so I tried to use .extend() but then realized that is only for lists that already exist. So I would have had to put the word into a list and then extract it with extend, and then delete the original word. This seemed more messy than working with loops so I decided to stick with loops. For part 2, I decided to try and make my code more readable by breaking down the steps into functions. So I used those helper functions in the main anagram checker function. I learned that I have to return the actual outputs in some cases since when I tried to sort the lists of characters, it was not permanent and it was then comparing None to None and always showing an anagram. In the original version it did not do that so it was good to learn.

Since I know that loops can be computationally expensive, I tried to use some quicker, less intensive checks to determine if there were issues before letting it get tot the loop. I checked that the inputs were actually strings (and not Int or float). I also checked the length of the words since they should be the same if they are anagrams. If not, it would exit early and give a response.

##Was there another approach you were thinking about making? If so, what approach(es) were you thinking of?

I tried to use .extend() function but realized it was for lists. For the second part I used more sub functions. The benefit of sub functions is that I could use them again in other code (had I had to write more larger functions).

Were there any challenges? If so, what issue(s) did you face? How did you overcome it?

Described above. I mostly used the examples in the repo and google to help figure out why my code was not working when I was using sub functions.

How were these changes tested?

I added some extra tests.

A reference to a related issue in your repository (if applicable)

Checklist

  • [ x] I can confirm that my changes are working as intended

Copy link
Copy Markdown

@juliagallucci juliagallucci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good. Your code is modular and readable, but it is overly verbose for a simple anagram check. Returning printed messages instead of a Boolean and using unnecessary loops makes it less efficient and harder to use! I’d suggest simplifying the function by removing unnecessary loops and directly using sorted(word_a) and sorted(word_b) for comparison, and returning a Boolean instead of printing messages!

…se in favour of more direct functions and boolean responses
…se in favour of more direct functions and boolean responses
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.

2 participants