- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlipArray.py
More file actions
Latest commit
14 lines (13 loc) · 580 Bytes
/
Copy pathFlipArray.py
File metadata and controls
14 lines (13 loc) · 580 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
importnumpy
defflip_list(lst):
"""
Create a function that flips a horizontal list into a vertical list,
and a vertical list into a horizontal list.
In other words, take an 1 x n list (1 row + n columns) and flip it into
a n x 1 list (n rows and 1 column), and vice versa.
"""
returnnumpy.reshape(lst, (numpy.array(lst).shape[0],1)) iflen(numpy.array(lst).shape) ==1elsenumpy.reshape(lst, (numpy.array(lst).shape[0],))
if__name__=="__main__":
print(flip_list([1, 2, 3, 4]))
print(flip_list([[5], [6], [9]]))
print(flip_list([]))