-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add a index slicing exercise to Python basics assignment #208
Conversation
@pkeilbach Is this fine for you? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking more of something like this, where students need to implemet variants of slicing (sorry I should have provided more instructions here):
# Function Prompt: Implement the following slicing operations
def slicing_examples(input_list):
"""
This function takes a list and returns a dictionary with results of different slicing operations.
Implement the following:
1. "first_three": Get the first three elements.
2. "last_two": Get the last two elements.
3. "reversed": Reverse the list.
4. "skip_two": Get every second element in the list.
5. "middle_slice": Get all elements except the first and last.
Args:
input_list (list): A list of elements.
Returns:
dict: A dictionary with keys as the operation names and values as the resulting sliced lists.
"""
# Example structure for the return dictionary
return {
"first_three": None, # Replace with slicing logic
"last_two": None, # Replace with slicing logic
"reversed": None, # Replace with slicing logic
"skip_two": None, # Replace with slicing logic
"middle_slice": None, # Replace with slicing logic
}
# Example usage:
# slicing_examples([1, 2, 3, 4, 5, 6])
# Expected output:
# {
# "first_three": [1, 2, 3],
# "last_two": [5, 6],
# "reversed": [6, 5, 4, 3, 2, 1],
# "skip_two": [1, 3, 5],
# "middle_slice": [2, 3, 4, 5]
# }
@pkeilbach I adjusted the function and the tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🚀
No description provided.