Question: from __future__ import annotations import random from typing import TYPE_CHECKING, List, Any from course import sort_students if TYPE_CHECKING: from survey import Survey from course import

from __future__ import annotations import random from typing import TYPE_CHECKING, List, Any from course import sort_students if TYPE_CHECKING: from survey import Survey from course import Course, Student

def slice_list(lst: List[Any], n: int) -> List[List[Any]]: """ Return a list containing slices of in order. Each slice is a list of size containing the next elements in .

The last slice may contain fewer than elements in order to make sure that the returned list contains all elements in .

=== Precondition === n <= len(lst)

>>> slice_list([3, 4, 6, 2, 3], 2) == [[3, 4], [6, 2], [3]] True >>> slice_list(['a', 1, 6.0, False], 3) == [['a', 1, 6.0], [False]] True """ ret = [] tmp = [] for i in range(len(lst)): if i % n == 0 and i != 0: tmp.append(lst[i]) if len(tmp) != 0: ret.append(tmp) tmp = [] return ret

def windows(lst: List[Any], n: int) -> List[List[Any]]: """ Return a list containing windows of in order. Each window is a list of size containing the elements with index i through index i+ in the original list where i is the index of window in the returned list.

=== Precondition === n <= len(lst)

>>> windows([3, 4, 6, 2, 3], 2) == [[3, 4], [4, 6], [6, 2], [2, 3]] True >>> windows(['a', 1, 6.0, False], 3) == [['a', 1, 6.0], [1, 6.0, False]] True """ ret = [] tmp = [] for i in range(n): tmp.append(lst[i]) ret.append(tmp) for i in range(len(lst)-n): tmp = tmp[1:] tmp.append(lst[i+n]) ret.append(tmp) return ret

I don't think the codes of these two methods are correct? Can you help me check these two methods and tell me the correct codes using python3.8? thankyou.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!