Skip to content

Commit 713ac85

Browse files
committed
Modify __repr__ method to use list comprehension.
1 parent 606b068 commit 713ac85

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

Diff for: Implementations/LinkedLists.py

+2-12
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,7 @@ def remove(val):
114114
"""
115115

116116
def __repr__(self) -> str:
117-
values = []
118-
119-
for node in self:
120-
values.append(str(node.data))
121-
122-
return "->".join(values)
117+
return "->".join([str(node.data) for node in self])
123118

124119
def insert(self, val, index: int = None):
125120
"""Insert a node containing the given value to the linked list in the specified index.
@@ -290,12 +285,7 @@ def remove(val):
290285
"""
291286

292287
def __repr__(self) -> str:
293-
values = []
294-
295-
for node in self:
296-
values.append(str(node.data))
297-
298-
return "<->".join(values)
288+
return "<->".join([str(node.data) for node in self])
299289

300290
def insert(self, val, index: int = None):
301291
"""Insert a node containing the given value to the linked list in the specified index.

0 commit comments

Comments
 (0)