Registry Synced

Jan 2026 - Python - Week 6 - Collections 1 - Graded

611 words
3 min read

Graded Assignment

Course: Jan 2026 - Python
Collections 1 - Graded
Submission deadline has passed for this assignment
Due Mar 25, 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
2/2 Passed
Submitted on Mar 25, 2026 at 2:30 PM IST
Private Tests
2/2 Passed
Submitted on Mar 25, 2026 at 2:30 PM 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.


Rotate a list K times**
Given a list of items and an integer k, rotate the list to the right by k steps.
Consider that the list contains at least one item.
Example
>>> rotate_list([1, 2, 3, 4, 5], 2)
[4, 5, 1, 2, 3]
Template Code(Click to Expand)

def rotate_list(lst: list, k: int) -> list:
    '''
    Given a list of items and an integer k, rotate the list to the right by k steps.


    Arguments:
    lst: list - a list of items
    k: int - the number of steps to rotate the list to the right

    Return:
    list - the rotated list
    '''
    ...

NOTE: You can use the below tools for working out and debugging. Click to open them in new tab.

Public Tests ( 2/2 )

Case 1

Input:
text
is_equal(
    rotate_list([1, 2, 3, 4, 5], 2),
    [4, 5, 1, 2, 3]
)
Expected Output:
text
[4, 5, 1, 2, 3]
Actual Output:
text
[4, 5, 1, 2, 3]

Case 2

Input:
text
is_equal(
    rotate_list(['a', 'b', 'c', 'd', 'e'], 3),
    ['c', 'd', 'e', 'a', 'b']
)
Expected Output:
text
['c', 'd', 'e', 'a', 'b']
Actual Output:
text
['c', 'd', 'e', 'a', 'b']

Private Tests ( 2/2 )

Case 1

Input:
text
is_equal(
    rotate_list([1, 2, 3, 4, 5], 0),
    [1, 2, 3, 4, 5]
)
is_equal(
    rotate_list(['a', 'b', 'c', 'd', 'e'], 27),
    ['d', 'e', 'a', 'b', 'c']
)
Expected Output:
text
[1, 2, 3, 4, 5]

['d', 'e', 'a', 'b', 'c']
Actual Output:
text
[1, 2, 3, 4, 5]

['d', 'e', 'a', 'b', 'c']

Case 2

Input:
text
is_equal(
    rotate_list([1, 2, 3, 4], 10),
    [3, 4, 1, 2]
)
is_equal(
    rotate_list([1], 10),
    [1]
)
Expected Output:
text
[3, 4, 1, 2]

[1]
Actual Output:
text
[3, 4, 1, 2]

[1]

💻 IITM Official Solution

python

def rotate_list(lst: list, k: int) -> list:
    '''
    Given a list of items and an integer k, rotate the list to the right by k steps.


    Arguments:
    lst: list - a list of items
    k: int - the number of steps to rotate the list to the right

    Return:
    list - the rotated list
    '''


    n = len(lst)
    k = k % n
    return lst[n-k:] + lst[:n-k]


💻 My Submitted Code

python

def rotate_list(lst: list, k: int) -> list:
    '''
    Given a list of items and an integer k, rotate the list to the right by k steps.


    Arguments:
    lst: list - a list of items
    k: int - the number of steps to rotate the list to the right

    Return:
    list - the rotated list
    '''
    ...

    n = len(lst)
    if n == 0:
        return lst

    k = k % n

    return lst[-k:] + lst[:-k]

Document Outline
Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.