Skip to content

Create sequences_aysegul_ezber.py #769

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
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Week03/sequences_aysegul_ezber.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def remove_duplicates(seq: list) -> list:
"""
This function removes duplicates from a list.
"""
return list(dict.fromkeys(seq)) # Using dict.fromkeys to remove duplicates while maintaining order.

def list_counts(seq: list) -> dict:
"""
This function counts the number of occurrences of each item in a list.
"""
return {item: seq.count(item) for item in set(seq)} # Counts occurrences by iterating over unique items in the list.

def reverse_dict(d: dict) -> dict:
"""
This function reverses the keys and values of a dictionary.
"""
return {v: k for k, v in d.items()} # Swaps keys and values to reverse the dictionary.
Loading