Welcome

Slicing List

Automated grading of homework assignments and tests

  • fork this repository
  • solve the task
  • commit with proper message

Problems

Slicing_list01

A list called numbers is given. Return the items in the odd index.

Example 1:

Input: list1=[1, 2, 3, 4, 5]
Output: [1,3,5]

Example 2:

Input: list1=[0, 1, 2, 3, 4, 5]
Output: [0, 2, 4]

Constraints:

  • 2 <= length(list1) <= 10^5

Slicing_list02

A list of several elements is given. Reverse this list.

Example 1:

Input: list1=[1, 2, 3, 4, 5]
Output: [5, 4, 3, 2, 1]

Example 2:

Input: list1=[0, 1, 2, 3, 4, 5]
Output: [5, 4, 3, 2, 1, 0]

Constraints:

  • 2 <= length(list1) <= 10^5

Slicing_list03

A list of several elements is given. Return this list by adding the reverse.

Example 1:

Input: list1=['a', 'b', 'c', 'd']
Output: ['a', 'b', 'c', 'd', 'd', 'c', 'b', 'a']

Example 2:

Input: list1=[0, 1, 2]
Output: [0, 1, 2, 2, 1, 0]

Constraints:

  • 2 <= length(list1) <= 10^5

Slicing_list04

A list of several elements is given. Return the three elements from the beginning.

Example 1:

Input: list1=['a', 'b', 'c', 'd']
Output: ['a', 'b', 'c']

Example 2:

Input: list1=['a', 1, 'b', 2, 'c', 3, 'd', 4]
Output: ['a', 1, 'b']

Constraints:

  • 4 <= length(list1) <= 10^5

Slicing_list05

A list of several elements is given. Return the value from n index to k index.

Example 1:

Input: list1=['a', 'b', 'c', 'd', 'e', 'f'] n = 2 k = 5
Output: ['c', 'd', 'e', 'f']

Example 2:

Input: list1=['a', 1, 'b', 2, 'c', 3, 'd', 4] n = 1 k = 3
Output: [1, 'b']

Constraints:

  • 4 <= length(list1) <= 10^5
  • 1 <= n <= k <= length(list1)

Slicing_list06

A list of several elements is given. Return the three elements from the beginning.

Example 1:

Input: list1=['a', 'b', 'c', 'd', 'e', 'f']
Output: ['a', 'd']

Example 2:

Input: list1=['a', 1, 'b', 2, 'c', 3, 'd', 4]
Output: ['a', 2, 'd']

Constraints:

  • 4 <= length(list1) <= 10^5

Slicing_list07

A list of several elements is given. Return all items from the beginning in n steps.

Example 1:

Input: list1=['a', 'b', 'c', 'd', 'e', 'f'] n = -1
Output: ['f', 'e', 'd', 'c', 'b', 'a']

Example 2:

Input: list1=['a', 1, 'b', 2, 'c', 3, 'd', 4] n = 2
Output: ['a', 'b', 'c', 'd']

Constraints:

  • 4 <= length(list1) <= 10^5
  • -1 <= n < length(list1)

Slicing_list08

A list of several elements is given. Return all items from end n steps.

Example 1:

Input: list1=['a', 'b', 'c', 'd', 'e', 'f'] n = -1
Output: ['a', 'b', 'c', 'd', 'e', 'f']

Example 2:

Input: list1=['a', 1, 'b', 2, 'c', 3, 'd', 4] n = 2
Output: [4, 3, 2, 1]

Constraints:

  • 4 <= length(list1) <= 10^5
  • -1 <= n <= length(list1)

Slicing_list09

A list of several elements is given. Return all items except n elements from the beginning.

Example 1:

Input: list1=['a', 'b', 'c', 'd', 'e', 'f'] n = 3
Output: ['d', 'e', 'f']

Example 2:

Input: list1=['a', 1, 'b', 2, 'c', 3, 'd', 4] n = 2
Output: ['b', 2, 'c', 3, 'd', 4]

Constraints:

  • 4 <= length(list1) <= 10^5
  • -1 <= n <= length(list1)

Slicing_list10

A list of several elements is given. Return all elements in reverse order except n elements from the beginning.

Example 1:

Input: list1=['a', 'b', 'c', 'd', 'e', 'f'] n = 3
Output: ['f', 'e', 'd']

Example 2:

Input: list1=['a', 1, 'b', 2, 'c', 3, 'd', 4] n = 2
Output: [4, 'd', 3, 'c', 2, 'b']

Constraints:

  • 4 <= length(list1) <= 10^5
  • -1 <= n <= length(list1)

Warning

  • don't copy other solutions or any solution
  • don't remove comments