Пример #1
0
	def test_insert_array1(self):
		""" -- Verifica la funcion insert
		"""
		arr=Array(10)
		arr[0]=10
		arr[1]=20
		arr[2]=30
		arr[3]=40
		#print(arr)
		insert(arr,15,2)
		res=arr[4]
		#print(res)
		self.assertEqual(res,40)
Пример #2
0
	def test_insert_element_out_of_range(self):
		"""  -- Insertar un elemento en la ultima posición de un array y se verifica que insert() devuelva None (error)
        """
		arr=Array(20,0)
		res=insert(arr,5,20)
		#print('devuelve:',res)
		self.assertEqual(res,None)
Пример #3
0
	def test_insert_element_empty_array(self):
		""" -- Insertar un elemento en un array vacio y se verifica que insert() devuelva None (error)
        """
		#arr=array(0,0)
		arr=[]
		res=insert(arr,1,2)
		#print('devuelve:',res)
		self.assertEqual(res,None)
Пример #4
0
import array as arr

ar = arr.array('d', [2, 3, 6, 7, 4, 8, 9])
print(ar)
arr.append(10)
arr.insert(1, 20)

# Python program to demonstrate
# Creation of Array

# importing "array" for array creations
import array as arr

# creating an array with integer type
a = arr.array('i', [1, 2, 3])

# printing original array
print("The new created array is : ", end=" ")
for i in range(0, 3):
    print(a[i], end=" ")
print()

# creating an array with float type
b = arr.array('d', [2.5, 3.2, 3.3])

# printing original array
print("The new created array is : ", end=" ")
for i in range(0, 3):
    print(b[i], end=" ")
Пример #5
0
# cerner_2^5_2020
"""
Given a fixed length array arr of integers, duplicate each occurrence of zero, shifting the remaining elements to the right.
Note that elements beyond the length of the original array are not written.
Do the above modifications to the input array in place, do not return anything from your function.
Example 1:
Input: [1,0,2,3,0,4,5,0]
Output: null
Explanation: After calling your function, the input array is modified to: [1,0,0,2,3,0,0,4]
Example 2:
Input: [1,2,3]
Output: null
Explanation: After calling your function, the input array is modified to: [1,2,3]
Note:
    1 <= arr.length <= 10000
    0 <= arr[i] <= 9
    https://leetcode.com/problems/duplicate-zeros/
"""
import array as arr

arr = [1,0,2,3,0,4,5,0]
#arr = [1,2,3]
#arr = [0,8,2]
i = 0
while i < len(arr):
    if arr[i] == 0
        arr.insert(i,0)
        arr.pop()
        i += 1
        print(arr)
Пример #6
0
import array as arr

arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]

arr.pop(6)
print(arr)
a = arr[2]
b = arr[6]
a, b = b, a
arr.insert(2, a)
arr.insert(6, b)
arr.pop(3)
arr.pop(7)
print(arr)