Skip to content

NW | 26-SDC-Mar | TzeMing Ho | Sprint 1 | Analyse and Refactor Functions#164

Open
TzeMingHo wants to merge 13 commits into
CodeYourFuture:mainfrom
TzeMingHo:coursework/analyse-and-refactor-functions
Open

NW | 26-SDC-Mar | TzeMing Ho | Sprint 1 | Analyse and Refactor Functions#164
TzeMingHo wants to merge 13 commits into
CodeYourFuture:mainfrom
TzeMingHo:coursework/analyse-and-refactor-functions

Conversation

@TzeMingHo

Copy link
Copy Markdown

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

I have attempted the exercises with comments to explain in big O, and tried to optimize the function if possible.

@TzeMingHo TzeMingHo added 📅 Sprint 1 Assigned during Sprint 1 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Jun 9, 2026

@cjyuan cjyuan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good. Well done.

Comment on lines +20 to +23
targetSet = set()

for num in numbers:
targetNum = target_sum - num

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Note: snake_case is the standard convention for variables and functions in Python.

unique_items.append(value)

return unique_items

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why not use the same approach you used in Sprint-1/JavaScript/removeDuplicates/removeDuplicates.mjs?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I tried to return list(set(values)). I thought it would have been the same as JavaScript. However, it can't pass the test, as the order of the list is different from the test case. So, I had to add the element to the list one by one.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Right. Python Set does not preserve order. There is, however, another built-in Python class that we can use to produce a single line solution.

Comment on lines +23 to +27
firstSet = {*first_sequence}

commonInSecond = filter(lambda item: item in firstSet, second_sequence)

return list({*commonInSecond}) No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could also use the built-in Set intersect operation.

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Jun 9, 2026
Comment on lines +25 to +27
common_in_second = filter(lambda item: item in first_set, second_sequence)

return list(set(common_in_second))

@cjyuan cjyuan Jun 10, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I meant, using this https://docs.python.org/3/library/stdtypes.html#frozenset.intersection
And there is even an overridden operator, &, for set intersection.

# return common_items

firstSet = {*first_sequence}
first_set = set(first_sequence)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Both of these syntaxes produces set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed. 📅 Sprint 1 Assigned during Sprint 1 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants