Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions names/names.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,19 @@
duplicates = [] # Return the list of duplicates in this data structure

# Replace the nested for loops below with your improvements
for name_1 in names_1:
for name_2 in names_2:
if name_1 == name_2:
duplicates.append(name_1)
# counter = 0
# while counter < 10000:
# if names_1[counter] in names_2:
# duplicates.append(names_1[counter])
# counter += int

for name in names_1:
if name in names_2:
duplicates.append(name)
# for name_1 in names_1:
# for name_2 in names_2:
# if name_1 == name_2:
# duplicates.append(name_1)

end_time = time.time()
print (f"{len(duplicates)} duplicates:\n\n{', '.join(duplicates)}\n\n")
Expand Down
15 changes: 14 additions & 1 deletion reverse/reverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,17 @@ def contains(self, value):
return False

def reverse_list(self, node, prev):
pass
# while current node is valid (not none)
while node != None:
# variable to keep track of the next node
nxt = node.get_next()
# assign 'cur.next' value to what ever 'prv' is (none for first iteration)
node.set_next(prev)
# assign 'prv' the current value of 'cur'
prev = node
# assign cur the value of next
node = nxt
# assign head the value of prv
# return prv which is
self.head = prev
return self.head
29 changes: 26 additions & 3 deletions ring_buffer/ring_buffer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@

class RingBuffer:
def __init__(self, capacity):
pass
self.capacity = capacity
self.storage = [None for i in range(capacity)]


def append(self, item):
pass
self.storage.pop(0)
self.storage.append(item)
print(self.storage)


def get(self):
pass
rtn = []

for i in self.storage:

if i is not None:
rtn.insert(0,i)
return rtn

b = RingBuffer(5)

b.append('a')
b.append('b')
b.append('c')
b.append('d')
b.append('e')
b.append('f')
b.append('g')
b.get()