Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def shiftLeft(data):
- pos = 1 # When shifting to the left we start at the left!
- # we start at position 1
- while pos < len(data):
- data[pos-1] = data[pos] # perform the shift
- pos = pos + 1
- # make the last item blank
- data[pos-1] = 0
- return data
- def shiftRight(data):
- pos = len(data) - 2 # When shifting to the left we start at the right!
- # we start at the second to last item
- while pos >=0:
- data[pos+1] = data[pos] # perform the shift
- pos = pos - 1
- # make the last item blank
- data[0] = 0
- return data
- # these are for 2d arrays (columns)
- def shiftDown(data, col):
- row = len(data) - 2 # When shifting to the left we start at the right!
- # we start at the second to last item
- while row >=0:
- data[row+1][col] = data[row][col] # perform the shift
- row = row - 1
- # make the last item blank
- data[0][col] = 0
- return data
- def display2D_array(data):
- row =0
- while row < len(data):
- rowArray = data[row]
- col =0
- temp = ""
- while col < len(rowArray):
- temp+=str(rowArray[col]) + " " * (3 - len(str(rowArray[col])))
- col +=1
- row +=1
- print(temp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement