Skip to content

Commit 8fbb779

Browse files
committed
use named tuple
1 parent 4fc7f7f commit 8fbb779

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

Python/chapter02/2.7 - Intersection/miguel_soln_2.7.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
node of the second linked list, then they are intersecting.
1010
"""
1111
import unittest
12-
from typing import Optional
12+
from typing import Optional, NamedTuple
1313

1414

1515
class Node:
@@ -174,23 +174,30 @@ def intersection(ll1: LinkedList, ll2: LinkedList) -> Optional[Node]:
174174
return None
175175

176176

177+
class SharedLLStructure(NamedTuple):
178+
first_segment: LinkedList
179+
second_segment: LinkedList
180+
shared_node: Node
181+
other_list: LinkedList
182+
183+
177184
class TestIntersection(unittest.TestCase):
178185

179186
def setUp(self):
180187
shared_structures = [
181-
(
188+
SharedLLStructure(
182189
LinkedList(1, 2, 3),
183190
LinkedList(5, 10, 11),
184191
Node(4),
185-
LinkedList(6, 7, 8, 9),
192+
LinkedList(6, 7, 8, 9)
186193
),
187-
(
194+
SharedLLStructure(
188195
LinkedList(1, 2, 3, 4, 5),
189196
LinkedList(7),
190197
Node(6),
191198
LinkedList(9, 8, 7),
192199
),
193-
(
200+
SharedLLStructure(
194201
LinkedList(1, 2),
195202
LinkedList(4, 5),
196203
Node(3),

0 commit comments

Comments
 (0)