Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6a53e9f

Browse files
Merge pull request avinashkranjan#200 from vaishnavijha/master
Script using ZIP function
2 parents 90e871f + 3956738 commit 6a53e9f

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

‎script_using_ZIP/transpose.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#how to get transpose of a matrix.
2+
# A normal coder may require some loops to get transpose but using ZIP function we can have it as one liner.
3+
# Know the Basic Usage of the Zip Function
4+
#The zip function aggregates items from different iterables, such as lists, tuples or sets, and returns an iterator.It works just like a physical zip.
5+
#In fact, the zip function in Python is much powerful than a physical zipper. It can deal with any number of iterables at once rather than just two.
6+
#Unfortunately, Python doesn’t have an unzip function. However, if we are familiar with the tricks of asterisks, unzipping is a very simple task.
7+
#In the above example, the asterisk did the unpacking operation, which is unpacking all the four tuples from the record list.
8+
9+
#main code
10+
matrix = [[1, 2, 3], [1, 2, 3]]#the inputted matrix
11+
matrix_T = [list(i) for i in zip(*matrix)]#one liner code for taking transpose of matrix
12+
print(matrix_T)#print to validate

‎script_using_ZIP/zip_readme.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Package/Script Name
2+
Python’s zip() function creates an iterator that will aggregate elements from two or more iterables. You can use the resulting iterator to quickly and consistently solve common programming problems, like creating dictionaries.
3+
4+
syntax of using zip:
5+
Python’s zip() function is defined as zip(*iterables). The function takes in iterables as arguments and returns an iterator. This iterator generates a series of tuples containing elements from each iterable. zip() can accept any type of iterable, such as files, lists, tuples, dictionaries, sets, and so on.
6+
7+
Output
8+
https://colab.research.google.com/drive/1fzVxXHEywdIx4BJu2ImN0mbC-gDR0UGJ?authuser=3#scrollTo=gfucILwOb9CF
9+
10+
Author(s)
11+
vaishnavi jha(SWOC)
12+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /