Answers for "subarray in python"

3

subarray in python

# arr[start (inclusive) : end (exclusive) : increment]
arr = [1, 2, 3, 4, 5]
a = arr[1 : 4]
b = arr[2 : ]  # Second idx defaults to len(arr)-1
c = arr[ : 3]  # First idx defaults to 0
d = arr[0 : 4 : 2]

print(a)  # [2, 3, 4]
print(b)  # [3, 4, 5]
print(c)  # [1, 2, 3]
print(d)  # [1, 3]
Posted by: Guest on March-31-2022
2

subarrays in python

array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
a = array[1 : 4]
b = array[0 : 8]
c = array[6 : ]
d = array[ : 5]
print(a)
print(b)
print(c)
print(d)
Posted by: Guest on April-13-2022

Python Answers by Framework

Browse Popular Code Answers by Language