Neural Sync Active
jan-2026-python-week-7-collections-1
Registry Synced
jan-2026-python-week-7-collections-1
683 words
3 min read
Collections 1
Course: Jan 2026 - Python
Collections 1
Submission deadline has passed for this assignment
Due Apr 01, 2026 at 11:59 PM IST
Instructions
Use "Test Run" to verify your code with public test cases.
Press "Submit" to have your assignment evaluated.
You can submit your assignment multiple times up until the deadline.
Make sure to submit your final code by the deadline to receive your score.
Summary
100 out of100
Score
Public Tests
3/3 Passed
Submitted on Apr 01, 2026 at 3:49 AM IST
Private Tests
3/3 Passed
Submitted on Apr 01, 2026 at 3:49 AM IST
**Change in eligibility criteria to write oppe2 exam: A5>=40/100 AND A6>=40/100 AND A7>=40/100 AND A8>=40/100. and becoming eligible to give the end term exam.
Reverse First half in an even length tuple**
Given an even-length tuple
t, return a new tuple where the first half of the tuple is reversed, and the second half remains unchanged.Example
t = (1, 2, 3, 4, 5, 6)
The first half
(1, 2, 3) is reversed to (3, 2, 1), so the result is (3, 2, 1, 4, 5, 6).Template Code(Click to Expand)
def reverse_first_half(t: tuple) -> tuple: ''' Given an even-length tuple, return a new tuple where the first half is reversed, and the second half remains unchanged. Arguments: t: tuple - an even-length tuple. Return: tuple - a new tuple with the first half reversed. ''' ...
NOTE: You can use the below tools for working out and debugging. Click to open them in new tab.
Public Tests ( 3/3 )
Case 1
Input:
textt = (10, 20, 30, 40, 50, 60) is_equal( reverse_first_half(t), (30, 20, 10, 40, 50, 60) )
Case 1
Expected Output:
text(30, 20, 10, 40, 50, 60)
Case 1
Actual Output:
text(30, 20, 10, 40, 50, 60)
Case 2
Input:
textt = ('a', 'b', 'c', 'd') is_equal( reverse_first_half(t), ('b', 'a', 'c', 'd') )
Case 2
Expected Output:
text('b', 'a', 'c', 'd')
Case 2
Actual Output:
text('b', 'a', 'c', 'd')
Case 3
Input:
textt = (1, 2) is_equal( reverse_first_half(t), (1, 2) )
Case 3
Expected Output:
text(1, 2)
Case 3
Actual Output:
text(1, 2)
Private Tests ( 3/3 )
Case 1
Input:
textt = (1, 2, 3, 4, 5, 6, 7, 8) is_equal( reverse_first_half(t), (4, 3, 2, 1, 5, 6, 7, 8) )
Case 1
Expected Output:
text(4, 3, 2, 1, 5, 6, 7, 8)
Case 1
Actual Output:
text(4, 3, 2, 1, 5, 6, 7, 8)
Case 2
Input:
textt = (100, 200, 300, 400) is_equal( reverse_first_half(t), (200, 100, 300, 400) )
Case 2
Expected Output:
text(200, 100, 300, 400)
Case 2
Actual Output:
text(200, 100, 300, 400)
Case 3
Input:
textt = (10, 20, 30, 40, 50, 60, 70, 80) is_equal( reverse_first_half(t), (40, 30, 20, 10, 50, 60, 70, 80) )
Case 3
Expected Output:
text(40, 30, 20, 10, 50, 60, 70, 80)
Case 3
Actual Output:
text(40, 30, 20, 10, 50, 60, 70, 80)
💻 IITM Official Solution
pythondef reverse_first_half(t: tuple) -> tuple: ''' Given an even-length tuple, return a new tuple where the first half is reversed, and the second half remains unchanged. Arguments: t: tuple - an even-length tuple. Return: tuple - a new tuple with the first half reversed. ''' mid = len(t) // 2 return t[:mid][::-1] + t[mid:]
💻 My Submitted Code
pythondef reverse_first_half(t: tuple) -> tuple: # 1. Find the midpoint mid = len(t) // 2 # 2. Slice the first half and reverse it using [::-1] first_half_reversed = t[:mid][::-1] # 3. Slice the second half (remains unchanged) second_half = t[mid:] # 4. Concatenate and return return first_half_reversed + second_half