Skip to content

Conversation

@evankchan
Copy link
Owner

UofT-DSI | Python - Assignment 1

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

I have added code (python) to build a function to compare if any two give are anagrams

What did you learn from the changes you have made?

I learned how to use statements such as if, elif, and else, as well as the incorporation of logical operators

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

My initial approach was very inefficient, in that i attempted to match each index of the first string to be compared to every other possible indices of the second string. This would have result in too many lines of code and only limited the functionality of the anagram to specific string lengths. Instead, I found out about the sorted() function and took this approach instead!

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

The main challenge I faced was the ordering of which "conditions" to test first. Should i compare string lengths first and than sort, or should i compare it the other way around? I decided to go with the former approach, as if both of the strings are of different lengths, than there is no point in comparing constituent elements of the strings :)

How were these changes tested?

I executed each code by code block. When I ran into an error, i debugged it first. At the very end, to make sure that everything executed, I ran the entire code.

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

N/A

Checklist

  • I can confirm that my changes are working as intended

Copy link

@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 attempt.
For part A, you should ignore cases (i.e., make them all upper or lower case)
For part B, there’s a small logical ordering issue in your elif statements that causes your current version to return False even when is_case_sensitive=False.
Please revise

…ordering and changed all words to lower case in the first part!
@juliagallucci
Copy link

no updates assignment file

Copy link

@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.

Great! One note for improvement, you don’t need to explicitly return True or False since the comparison itself already evaluates to a Boolean

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.

3 participants