Skip to content

Use list instead of tuple in variable swapping exercise#346

Merged
valentina-s merged 1 commit intoswcarpentry:gh-pagesfrom
tv3141:variable_swapping_exercise_using_list
Feb 3, 2017
Merged

Use list instead of tuple in variable swapping exercise#346
valentina-s merged 1 commit intoswcarpentry:gh-pagesfrom
tv3141:variable_swapping_exercise_using_list

Conversation

@tv3141
Copy link
Copy Markdown

@tv3141 tv3141 commented Jan 15, 2017

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]

> 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]
@valentina-s
Copy link
Copy Markdown
Contributor

Thanks, I agree that using a list is more clear (I think these were remnants from the old lessons which introduced tuples).

@valentina-s valentina-s merged commit 7b04c07 into swcarpentry:gh-pages Feb 3, 2017
rgaiacs pushed a commit to rgaiacs/swc-python-novice-inflammation that referenced this pull request May 6, 2017
Update lesson objectives of lesson on them
zkamvar pushed a commit that referenced this pull request Apr 21, 2023
…list

Use list instead of tuple in variable swapping exercise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants