def Reverse(array): array.reverse() for ar in array: ar.reverse() return array
def test_mixed_dot_product(self): dim = 10 sv = [(1, 0.4), (3, -0.1), (6, 0.8), (9, 0)] dv = array('b', [1, 1, 1, 1, 1, -1, -1, -1, -1, -1]) dp1 = sketchy.mixed_dot_product(sv, dv) # 0.4 * 1 + -0.1 * 1 + 0.8 * -1 + 0 * -1 self.assertEqual(-0.5, dp1) array.reverse(dv) dp2 = sketchy.mixed_dot_product(sv, dv) # 0.4 * -1 + -0.1 * -1 + 0.8 * 1 + 0 * 1 self.assertEqual(0.5, dp2)
from array import array a = array('H', [4000, 10, 700, 22222 ]) #from the module "array", array() function is called print a print sum(a) #26932 print "------------------------------------" print dir(array) print "------------------------------------" array.reverse(a) print a ''' The array module provides an array() object that is like a list that stores only homogeneous data and stores it more compactly. ''' #print a[1:3] #array('H', [10, 700])
else: print("fulfilled stack") # Queue -> First In - First Out queue = deque([]) queue.append(1) queue.append(2) queue.popleft() # Removes FIRST # Array array = array("i", [1, 2, 3]) array.reverse() # Doesn't return the reversed, it reverses the array directly # Sets -> Unique values - Are objects uniques = set([1, 2, 3, 4, 4, 5]) uniques.add(5) # Combining UNIQUE sets secondUniques = {1, 5, 7} # Returns new set with all the values that exists in each set print(uniques | secondUniques) # Returns new set with only the values that exists in both sets print(uniques & secondUniques) # Returns new set with the values that exists in the left set but not in the right set print(uniques - secondUniques) # Returns the values that are either on the left o right set but NOT IN BOTH