Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Computer Science Introduction to Data Structures Merge Sort and Linked Lists The Conquer Step

@11:50 DRY principle in replacing merged head to next node head ?

@ 11:50 Pasan writes the following code:

   # Discard fake head and set first merged node as head
   head = merged.head.next_node
   merged.head = head

But can't it be simplified to the following?

   # Discard fake head and set first merged node as head
   merged.head = merged.head.next_node 

1 Answer

Steven Parker
Steven Parker
231,172 Points

You can save a line (and a variable) this way, but having the same term on both sides of an assignment might not be as clear as doing it in two steps.

Either way, the "DRY" principle doesn't apply here, since nothing is being repeated.