From 0a8669fbbe5e910e43acd63200258e921161d844 Mon Sep 17 00:00:00 2001 From: Pravin Pratap Date: Wed, 31 Oct 2018 06:31:00 +0530 Subject: [PATCH] Added another code sample. (#20499) Added a code sample to demonstrate usage of the zip function with a list of lists. --- guide/english/python/zip-function/index.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/guide/english/python/zip-function/index.md b/guide/english/python/zip-function/index.md index 1ca78311a69..76313142f5f 100644 --- a/guide/english/python/zip-function/index.md +++ b/guide/english/python/zip-function/index.md @@ -9,14 +9,20 @@ Any number of iterables separated by comma. ## Return Value -A list of tuple of nth element from all sequences +A list of tuples of nth element(s) from all sequences ## Code Sample - nums = [1,2,3,4] - print(*nums) # prints 1 2 3 4 + # Example 1 : zipping 2 lists. numsAndNames = zip([1,2,3],['one','two','three']) print(*numsAndNames) # prints (1,'one') (2,'two') (3,'three') + + # Example 2 : zipping a list of lists. + list_of_lists = [[1,2,3,4,5],[6,7,8,9,0],[10,11,12,13,14,15]] + lists_zip = zip(*list_of_lists) + print(*lists_zip) # prints (1,6,10) (2,7,11) (3,8,12) (4,9,13) (5,0,14) + # Notice how the 15 from the last list is truncated. + ![:rocket:](//forum.freecodecamp.com/images/emoji/emoji_one/rocket.png?v=2 ":rocket:") Run Code