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)
# for name_1 in names_1:
# for name_2 in names_2:
# if name_1 == name_2:
# duplicates.append(name_1)

def intersection(lst1, lst2):

# Use of hybrid method
temp = set(lst2)
lst3 = [value for value in lst1 if value in temp]
return lst3

duplicates = intersection(names_1, names_2)

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

def reverse_list(self, node, prev):
pass
prev = None
current = self.head
while(current is not None):
next_node = current.next_node
current.next_node = prev
prev = current
current = next_node
self.head = prev
20 changes: 16 additions & 4 deletions ring_buffer/ring_buffer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
class RingBuffer:
def __init__(self, capacity):
pass
self.capacity = capacity
self.data = []
self.current = 0

def append(self, item):
pass
def append(self,item):
if len(self.data) == self.capacity:
print(f"data: {self.data}, current:{self.current}")
self.data[self.current] = item

if [self.current] == [self.capacity-1]:
self.current = 0
else:
self.current += 1

else:
self.data.append(item)

def get(self):
pass
return self.data