Skip to content

Commit a00db22

Browse files
author
Your Name
committed
Use list instead of tuple in variable swapping exercise.
> right, left = left, right > "...we pack right and left into a tuple and then unpack it again into left > and right." This example for variable value swapping introduces three new concepts: 1. the tuple data type 2. special tuple syntax, omitting parentheses 3. container unpacking in an assignment I think using a list is much clearer, and only introduces the concept of container unpacking. right, left = [left, right]
1 parent 4f56886 commit a00db22

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

_episodes/03-lists.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ Omitting ending index: ["sep", "oct", "nov", "dec"]
468468
> Compare it to:
469469
>
470470
> ~~~
471-
> left, right = right, left
471+
> left, right = [right, left]
472472
> ~~~
473473
> {: .python}
474474
>
@@ -488,7 +488,7 @@ Omitting ending index: ["sep", "oct", "nov", "dec"]
488488
> > ~~~
489489
> > {: .output}
490490
> >
491-
> >In the first case we used a temporary variable `temp` to keep the value of `left` before we overwrite it with the value of `right`. In the second case, we pack `right` and `left` into a tuple and then unpack it again into `left` and `right`.
491+
> >In the first case we used a temporary variable `temp` to keep the value of `left` before we overwrite it with the value of `right`. In the second case, `right` and `left` are packed into a list and then unpacked into `left` and `right`.
492492
> {: .solution}
493493
{: .challenge}
494494

0 commit comments

Comments
 (0)