Skip to content

Instantly share code, notes, and snippets.

@ashutoshkrris
Created April 6, 2022 04:24
Show Gist options
  • Save ashutoshkrris/4cc743c6202e5bf18ccf846e57899559 to your computer and use it in GitHub Desktop.
Save ashutoshkrris/4cc743c6202e5bf18ccf846e57899559 to your computer and use it in GitHub Desktop.
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