<jupyter_start><jupyter_text>Problem- You have a sequence for which the lenght is known, with each element representing a specific information depending on its index- How do you get access to each piece of information in the sequence without using indexing syntax<jupyter_code>comment = ('Junior', 'Python3 is awesome', 5, (8, 5, 2019))
comment<jupyter_output><empty_output><jupyter_text>Answer- Use sequence unpacking<jupyter_code>comment_author, comment_content, likes, date = comment #<0>
print(comment_author)
print(comment_content)
print(likes)
print(date)

reconstructed_comment = comment_author, comment_content, likes, date
print(reconstructed_comment)
_, comment_content, _, (day, month, year) = comment #<1>
print(comment_content)
print(day)
print(month)
print(year)<jupyter_output>Python3 is awesome
8
5
2019<jupyter_text>Discussion-  we are able to unpack each specific information according to its position in the sequence-  we can even unpack nested elements like the day, month and year in the date and ignore some elements if we want to using underscore _  Problem- You have a sequence for which the lenght is unknown, but you know useful informations are usually located at the ends- How do you get access to the head or tail element of a sequence for which the length is not known<jupyter_code># getting the best and worse reviews of different movies
reviews_movie1 = sorted([3.1, 4.5, 2.6, 4.8]) #<0>
reviews_movie2 = sorted([5.0, 4.2, 3.4, 2.1, 4.1, 4.7, 3.9]) #<0>

print(reviews_movie1)
print(reviews_movie2)<jupyter_output>[2.6, 3.1, 4.5, 4.8]
[2.1, 3.4, 3.9, 4.1, 4.2, 4.7, 5.0]<jupyter_text>Answer-  Use sequence unpacking<jupyter_code>worse_movie1, *middle, best_movie1 = reviews_movie1 #<1>

print(worse_movie1)
print(best_movie1)
print(middle)
worse_movie2, *_, best_movie2 = reviews_movie2 #<2>
print(worse_movie2)
print(best_movie2)<jupyter_output>2.1
5.0
{'fraction_non_alphanumeric': 0.09761273209549072, 'fraction_numerical': 0.04403183023872679, 'mean_word_length': 6.037313432835821, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '274801', 'license': 'MIT', 'n_tokens_mistral': 696, 'n_tokens_neox': 636, 'n_words': 217, 'path': 'python3_recipes/notebooks/_1_Sequences/_5_sequence_unpacking.ipynb', 'repo_name': 'geekgap-io/python3_recipes', 'size': '1885'}