Skip to content

UofT-DSI | Python - Assignment 1#1

Open
brianna-lowe wants to merge 1 commit intomainfrom
assignment-1
Open

UofT-DSI | Python - Assignment 1#1
brianna-lowe wants to merge 1 commit intomainfrom
assignment-1

Conversation

@brianna-lowe
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 expanded the existing anagram_checker function to include a new boolean parameter called is_case_sensitive. Based on this parameter, the function should either compare the words exactly as written (case sensitive) or compare lowercase versions of the words (not case sensitive).

What did you learn from the changes you have made?

I learned how Python handles boolean values differently from strings and how important indentation is for maintaining proper control flow. I also learned the difference between sorted() vs .sort(), how return statements stop code execution, and how to structure a function so all conditions are reachable

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

Yes, I considered creating separate helper functions. One for case-sensitive comparison and another for non-case-sensitive comparison and calling them based on the boolean value. I also thought about converting the words first and storing them in temporary variables before comparing.

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

Yes, I ran into indentation errors that caused the else blocks to be misaligned.
I also initially compared boolean values as strings ('True' instead of True).
I corrected these issues by aligning the if/else blocks properly, removing unreachable code, and ensuring I used boolean logic correctly (if is_case_sensitive:).

How were these changes tested?

I tested the function using multiple word pairs provided and all test returned the expected results.

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

N/A

Checklist

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

Copy link

@xindizhang xindizhang left a comment

Choose a reason for hiding this comment

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

Excellent work! Your code is clean, well-documented, and well-written and your PR description is clear. Your assignment 1 is complete – no changes needed.

Please see my minor suggestion for future improvement:

  • In places like:
  if sorted(word_a.lower()) == sorted(word_b.lower()): #added lower because I inadvertently made a case sensitive anagram checker if sorted (word_a) == sorted(word_b)
    return True  
  else:
    return False

You can simplify this by directly returning the boolean expression:
return sorted(word_a.lower()) == sorted(word_b.lower())
This makes the code cleaner

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