-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackpack.py
49 lines (39 loc) · 1.09 KB
/
backpack.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class BackPack:
"""
BackPack Class
ToDo: [X] Instantiate backpack
ToDo: [X] Add Item
ToDo: [ ] Remove Item
ToDo: [ ] List Items
ToDo: [X] Count items
ToDo: [ ] in backpack (Search for Item - Student to do)
ToDo: [X] Sort Items
"""
def __init__(self, items):
self._backpack = []
if items is None:
items = []
if type(items) is not "<class 'list'>":
items = []
for item in items:
self._backpack.append(item)
self.sort()
def sort(self):
self._backpack.sort()
def count(self):
return self._backpack.count()
def list(self):
pass
def add(self, item):
if item is not None:
self._backpack.append(item)
self.sort()
def in_backpack(self, item):
"""
Complete this method using a binary search
returns -1 or False if not found
returns position if found
:param item:
:return: -1 | False | integer
"""
return None