Created
April 6, 2022 04:24
-
-
Save ashutoshkrris/4cc743c6202e5bf18ccf846e57899559 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
post_data = [1, 'Getting started with Rich', ('Ashutosh Krishna', 22, 'India')] | |
# General Way, Don't Do ❌ | |
post_id = post_data[0] | |
post_title = post_data[1] | |
author_data = post_data[2] | |
author_name = author_data[0] | |
author_age = author_data[1] | |
author_country = author_data[2] | |
print(post_id, post_title) | |
print(author_name, author_age, author_country) | |
# Better Way ✅ | |
# Unpack the list first | |
post_id, post_title, author_data = post_data | |
# Unpack the tuple | |
author_name, author_age, author_country = author_data | |
print(post_id, post_title) | |
print(author_name, author_age, author_country) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment