Advertisement
Ridz112

Untitled

Jan 19th, 2021
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1. def shiftLeft(data):
  2.     pos = 1 # When shifting to the left we start at the left!
  3.     # we start at position 1
  4.     while pos < len(data):
  5.         data[pos-1] = data[pos] # perform the shift
  6.         pos = pos + 1
  7.     # make the last item blank
  8.     data[pos-1] = 0
  9.     return data
  10.  
  11. def shiftRight(data):
  12.     pos = len(data) - 2 # When shifting to the left we start at the right!
  13.     # we start at the second to last item
  14.     while pos >=0:
  15.         data[pos+1] = data[pos] # perform the shift
  16.         pos = pos - 1
  17.     # make the last item blank
  18.     data[0] = 0
  19.     return data
  20.  
  21. # these are for 2d arrays (columns)
  22. def shiftDown(data, col):
  23.     row = len(data) - 2 # When shifting to the left we start at the right!
  24.     # we start at the second to last item
  25.     while row >=0:
  26.         data[row+1][col] = data[row][col] # perform the shift
  27.         row = row - 1
  28.     # make the last item blank
  29.     data[0][col] = 0
  30.     return data
  31.  
  32. def display2D_array(data):
  33.     row =0
  34.     while row < len(data):
  35.         rowArray = data[row]
  36.         col =0
  37.         temp = ""
  38.         while col < len(rowArray):
  39.             temp+=str(rowArray[col]) + " " * (3 - len(str(rowArray[col])))
  40.             col +=1
  41.         row +=1
  42.         print(temp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement