From 901056c8168cdd450252d2242637b00f35363a22 Mon Sep 17 00:00:00 2001 From: Teja Reddy Alla Date: Wed, 1 Jan 2025 17:02:44 -0800 Subject: [PATCH] zip-two-lists in python --- snippets/python/list-manipulation/zip-two-lists | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 snippets/python/list-manipulation/zip-two-lists diff --git a/snippets/python/list-manipulation/zip-two-lists b/snippets/python/list-manipulation/zip-two-lists new file mode 100644 index 00000000..dee9bfc1 --- /dev/null +++ b/snippets/python/list-manipulation/zip-two-lists @@ -0,0 +1,16 @@ +--- +title: Zip two lists +description: Combines the corresponding elements of lists into a new list +author: TejaReddyAlla +tags: python,list,zip,utility +--- + +```py +def zip_lists(lst1, lst2): + return list(zip(lst1, lst2)) + +# Usage: +lst1 = [1, 2, 3] +lst2 = ['a', 'b', 'c'] +print(zip_lists(lst1, lst2)) # Output: [(1, 'a'), (2, 'b'), (3, 'c')] +```