Submit Search
Upload
Python Programming Essentials - M34 - List Comprehensions
•
2 likes
•
762 views
P3 InfoTech Solutions Pvt. Ltd.
Follow
Slides from the training on the topic "Python Programming Essentials"
Read less
Read more
Report
Share
Report
Share
1 of 12
Recommended
Python Programming Essentials - M17 - Functions
Python Programming Essentials - M17 - Functions
P3 InfoTech Solutions Pvt. Ltd.
Advanced python
Advanced python
EU Edge
Cpp tutorial
Cpp tutorial
FALLEE31188
Docopt
Docopt
René Ribaud
Advanced Python, Part 1
Advanced Python, Part 1
Zaar Hai
Imugi: Compiler made with Python
Imugi: Compiler made with Python
Han Lee
INTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHON
vikram mahendra
A tour of Python
A tour of Python
Aleksandar Veselinovic
Recommended
Python Programming Essentials - M17 - Functions
Python Programming Essentials - M17 - Functions
P3 InfoTech Solutions Pvt. Ltd.
Advanced python
Advanced python
EU Edge
Cpp tutorial
Cpp tutorial
FALLEE31188
Docopt
Docopt
René Ribaud
Advanced Python, Part 1
Advanced Python, Part 1
Zaar Hai
Imugi: Compiler made with Python
Imugi: Compiler made with Python
Han Lee
INTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHON
vikram mahendra
A tour of Python
A tour of Python
Aleksandar Veselinovic
Arrry structure Stacks in data structure
Arrry structure Stacks in data structure
lodhran-hayat
Scalapeno18 - Thinking Less with Scala
Scalapeno18 - Thinking Less with Scala
Daniel Sebban
friends functionToshu
friends functionToshu
Sidd Singh
USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2
vikram mahendra
Operator overloading
Operator overloading
piyush Kumar Sharma
Introduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in Haskell
nebuta
Ds lab handouts
Ds lab handouts
Ayesha Bhatti
#OOP_D_ITS - 2nd - C++ Getting Started
#OOP_D_ITS - 2nd - C++ Getting Started
Hadziq Fabroyir
Unit2 input output
Unit2 input output
deepak kumbhar
Introduction to cython
Introduction to cython
John(Qiang) Zhang
Advanced Python, Part 2
Advanced Python, Part 2
Zaar Hai
Composing an App with Free Monads (using Cats)
Composing an App with Free Monads (using Cats)
Hermann Hueck
Dynamic memory allocation in c++
Dynamic memory allocation in c++
Tech_MX
Lecture 4, c++(complete reference,herbet sheidt)chapter-14
Lecture 4, c++(complete reference,herbet sheidt)chapter-14
Abu Saleh
Python programming workshop session 1
Python programming workshop session 1
Abdul Haseeb
Programs of C++
Programs of C++
The University of Faisalabad; Madina University
Python Programming Essentials - M16 - Control Flow Statements and Loops
Python Programming Essentials - M16 - Control Flow Statements and Loops
P3 InfoTech Solutions Pvt. Ltd.
Python Part 1
Python Part 1
Sunil OS
Ruby on rails tips
Ruby on rails tips
BinBin He
Advance C++notes
Advance C++notes
Rajiv Gupta
Python Programming Essentials - M44 - Overview of Web Development
Python Programming Essentials - M44 - Overview of Web Development
P3 InfoTech Solutions Pvt. Ltd.
The One Way
The One Way
Daniel Greenfeld
More Related Content
What's hot
Arrry structure Stacks in data structure
Arrry structure Stacks in data structure
lodhran-hayat
Scalapeno18 - Thinking Less with Scala
Scalapeno18 - Thinking Less with Scala
Daniel Sebban
friends functionToshu
friends functionToshu
Sidd Singh
USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2
vikram mahendra
Operator overloading
Operator overloading
piyush Kumar Sharma
Introduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in Haskell
nebuta
Ds lab handouts
Ds lab handouts
Ayesha Bhatti
#OOP_D_ITS - 2nd - C++ Getting Started
#OOP_D_ITS - 2nd - C++ Getting Started
Hadziq Fabroyir
Unit2 input output
Unit2 input output
deepak kumbhar
Introduction to cython
Introduction to cython
John(Qiang) Zhang
Advanced Python, Part 2
Advanced Python, Part 2
Zaar Hai
Composing an App with Free Monads (using Cats)
Composing an App with Free Monads (using Cats)
Hermann Hueck
Dynamic memory allocation in c++
Dynamic memory allocation in c++
Tech_MX
Lecture 4, c++(complete reference,herbet sheidt)chapter-14
Lecture 4, c++(complete reference,herbet sheidt)chapter-14
Abu Saleh
Python programming workshop session 1
Python programming workshop session 1
Abdul Haseeb
Programs of C++
Programs of C++
The University of Faisalabad; Madina University
Python Programming Essentials - M16 - Control Flow Statements and Loops
Python Programming Essentials - M16 - Control Flow Statements and Loops
P3 InfoTech Solutions Pvt. Ltd.
Python Part 1
Python Part 1
Sunil OS
Ruby on rails tips
Ruby on rails tips
BinBin He
Advance C++notes
Advance C++notes
Rajiv Gupta
What's hot
(20)
Arrry structure Stacks in data structure
Arrry structure Stacks in data structure
Scalapeno18 - Thinking Less with Scala
Scalapeno18 - Thinking Less with Scala
friends functionToshu
friends functionToshu
USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2
Operator overloading
Operator overloading
Introduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in Haskell
Ds lab handouts
Ds lab handouts
#OOP_D_ITS - 2nd - C++ Getting Started
#OOP_D_ITS - 2nd - C++ Getting Started
Unit2 input output
Unit2 input output
Introduction to cython
Introduction to cython
Advanced Python, Part 2
Advanced Python, Part 2
Composing an App with Free Monads (using Cats)
Composing an App with Free Monads (using Cats)
Dynamic memory allocation in c++
Dynamic memory allocation in c++
Lecture 4, c++(complete reference,herbet sheidt)chapter-14
Lecture 4, c++(complete reference,herbet sheidt)chapter-14
Python programming workshop session 1
Python programming workshop session 1
Programs of C++
Programs of C++
Python Programming Essentials - M16 - Control Flow Statements and Loops
Python Programming Essentials - M16 - Control Flow Statements and Loops
Python Part 1
Python Part 1
Ruby on rails tips
Ruby on rails tips
Advance C++notes
Advance C++notes
Viewers also liked
Python Programming Essentials - M44 - Overview of Web Development
Python Programming Essentials - M44 - Overview of Web Development
P3 InfoTech Solutions Pvt. Ltd.
The One Way
The One Way
Daniel Greenfeld
PyCon Philippines 2012 Keynote
PyCon Philippines 2012 Keynote
Daniel Greenfeld
Intro to Data Visualizations
Intro to Data Visualizations
Daniel Greenfeld
Intro
Intro
Daniel Greenfeld
Lighting talk on django-social-auth
Lighting talk on django-social-auth
Daniel Greenfeld
Python Programming Essentials - M37 - Brief Overview of Misc Concepts
Python Programming Essentials - M37 - Brief Overview of Misc Concepts
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M25 - os and sys modules
Python Programming Essentials - M25 - os and sys modules
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M29 - Python Interpreter and Files
Python Programming Essentials - M29 - Python Interpreter and Files
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M35 - Iterators & Generators
Python Programming Essentials - M35 - Iterators & Generators
P3 InfoTech Solutions Pvt. Ltd.
Round pegs and square holes
Round pegs and square holes
Daniel Greenfeld
Python Programming Essentials - M39 - Unit Testing
Python Programming Essentials - M39 - Unit Testing
P3 InfoTech Solutions Pvt. Ltd.
An Extreme Talk about the Zen of Python
An Extreme Talk about the Zen of Python
Daniel Greenfeld
Python Programming Essentials - M40 - Invoking External Programs
Python Programming Essentials - M40 - Invoking External Programs
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M28 - Debugging with pdb
Python Programming Essentials - M28 - Debugging with pdb
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M31 - PEP 8
Python Programming Essentials - M31 - PEP 8
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M5 - Variables
Python Programming Essentials - M5 - Variables
P3 InfoTech Solutions Pvt. Ltd.
How to Write a Popular Python Library by Accident
How to Write a Popular Python Library by Accident
Daniel Greenfeld
Thinking hard about_python
Thinking hard about_python
Daniel Greenfeld
Intro to Python
Intro to Python
Daniel Greenfeld
Viewers also liked
(20)
Python Programming Essentials - M44 - Overview of Web Development
Python Programming Essentials - M44 - Overview of Web Development
The One Way
The One Way
PyCon Philippines 2012 Keynote
PyCon Philippines 2012 Keynote
Intro to Data Visualizations
Intro to Data Visualizations
Intro
Intro
Lighting talk on django-social-auth
Lighting talk on django-social-auth
Python Programming Essentials - M37 - Brief Overview of Misc Concepts
Python Programming Essentials - M37 - Brief Overview of Misc Concepts
Python Programming Essentials - M25 - os and sys modules
Python Programming Essentials - M25 - os and sys modules
Python Programming Essentials - M29 - Python Interpreter and Files
Python Programming Essentials - M29 - Python Interpreter and Files
Python Programming Essentials - M35 - Iterators & Generators
Python Programming Essentials - M35 - Iterators & Generators
Round pegs and square holes
Round pegs and square holes
Python Programming Essentials - M39 - Unit Testing
Python Programming Essentials - M39 - Unit Testing
An Extreme Talk about the Zen of Python
An Extreme Talk about the Zen of Python
Python Programming Essentials - M40 - Invoking External Programs
Python Programming Essentials - M40 - Invoking External Programs
Python Programming Essentials - M28 - Debugging with pdb
Python Programming Essentials - M28 - Debugging with pdb
Python Programming Essentials - M31 - PEP 8
Python Programming Essentials - M31 - PEP 8
Python Programming Essentials - M5 - Variables
Python Programming Essentials - M5 - Variables
How to Write a Popular Python Library by Accident
How to Write a Popular Python Library by Accident
Thinking hard about_python
Thinking hard about_python
Intro to Python
Intro to Python
Similar to Python Programming Essentials - M34 - List Comprehensions
The Java Fx Platform – A Java Developer’S Guide
The Java Fx Platform – A Java Developer’S Guide
Stephen Chin
Computer Science Sample Paper 2015
Computer Science Sample Paper 2015
Poonam Chopra
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Edureka!
Benchy: Lightweight framework for Performance Benchmarks
Benchy: Lightweight framework for Performance Benchmarks
Marcel Caraciolo
Introduction to biopython
Introduction to biopython
Suhad Jihad
Nalinee java
Nalinee java
Nalinee Choudhary
TDD CrashCourse Part3: TDD Techniques
TDD CrashCourse Part3: TDD Techniques
David Rodenas
Mysql python
Mysql python
Janu Jahnavi
Mysql python
Mysql python
Janu Jahnavi
Python - Lecture 12
Python - Lecture 12
Ravi Kiran Khareedi
PPT on Data Science Using Python
PPT on Data Science Using Python
NishantKumar1179
Lec3
Lec3
Saad Gabr
Auto testing!
Auto testing!
Kwangsoo Shin
CBSE Question Paper Computer Science with C++ 2011
CBSE Question Paper Computer Science with C++ 2011
Deepak Singh
lab-assgn-practical-file-xii-cs.pdf
lab-assgn-practical-file-xii-cs.pdf
JeevithaG22
report
report
Quickoffice Test
C sharp 8.0 new features
C sharp 8.0 new features
MSDEVMTL
C sharp 8.0 new features
C sharp 8.0 new features
Miguel Bernard
C# Tutorial MSM_Murach chapter-08-slides
C# Tutorial MSM_Murach chapter-08-slides
Sami Mut
Class 12 computer sample paper with answers
Class 12 computer sample paper with answers
debarghyamukherjee60
Similar to Python Programming Essentials - M34 - List Comprehensions
(20)
The Java Fx Platform – A Java Developer’S Guide
The Java Fx Platform – A Java Developer’S Guide
Computer Science Sample Paper 2015
Computer Science Sample Paper 2015
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Benchy: Lightweight framework for Performance Benchmarks
Benchy: Lightweight framework for Performance Benchmarks
Introduction to biopython
Introduction to biopython
Nalinee java
Nalinee java
TDD CrashCourse Part3: TDD Techniques
TDD CrashCourse Part3: TDD Techniques
Mysql python
Mysql python
Mysql python
Mysql python
Python - Lecture 12
Python - Lecture 12
PPT on Data Science Using Python
PPT on Data Science Using Python
Lec3
Lec3
Auto testing!
Auto testing!
CBSE Question Paper Computer Science with C++ 2011
CBSE Question Paper Computer Science with C++ 2011
lab-assgn-practical-file-xii-cs.pdf
lab-assgn-practical-file-xii-cs.pdf
report
report
C sharp 8.0 new features
C sharp 8.0 new features
C sharp 8.0 new features
C sharp 8.0 new features
C# Tutorial MSM_Murach chapter-08-slides
C# Tutorial MSM_Murach chapter-08-slides
Class 12 computer sample paper with answers
Class 12 computer sample paper with answers
More from P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M27 - Logging module
Python Programming Essentials - M27 - Logging module
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M24 - math module
Python Programming Essentials - M24 - math module
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M23 - datetime module
Python Programming Essentials - M23 - datetime module
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M22 - File Operations
Python Programming Essentials - M22 - File Operations
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M21 - Exception Handling
Python Programming Essentials - M21 - Exception Handling
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M20 - Classes and Objects
Python Programming Essentials - M20 - Classes and Objects
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M19 - Namespaces, Global Variables and Docstr...
Python Programming Essentials - M19 - Namespaces, Global Variables and Docstr...
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M18 - Modules and Packages
Python Programming Essentials - M18 - Modules and Packages
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M15 - References
Python Programming Essentials - M15 - References
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M14 - Dictionaries
Python Programming Essentials - M14 - Dictionaries
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M13 - Tuples
Python Programming Essentials - M13 - Tuples
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M12 - Lists
Python Programming Essentials - M12 - Lists
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M11 - Comparison and Logical Operators
Python Programming Essentials - M11 - Comparison and Logical Operators
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M10 - Numbers and Artihmetic Operators
Python Programming Essentials - M10 - Numbers and Artihmetic Operators
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M9 - String Formatting
Python Programming Essentials - M9 - String Formatting
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M8 - String Methods
Python Programming Essentials - M8 - String Methods
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M7 - Strings
Python Programming Essentials - M7 - Strings
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M6 - Code Blocks and Indentation
Python Programming Essentials - M6 - Code Blocks and Indentation
P3 InfoTech Solutions Pvt. Ltd.
More from P3 InfoTech Solutions Pvt. Ltd.
(18)
Python Programming Essentials - M27 - Logging module
Python Programming Essentials - M27 - Logging module
Python Programming Essentials - M24 - math module
Python Programming Essentials - M24 - math module
Python Programming Essentials - M23 - datetime module
Python Programming Essentials - M23 - datetime module
Python Programming Essentials - M22 - File Operations
Python Programming Essentials - M22 - File Operations
Python Programming Essentials - M21 - Exception Handling
Python Programming Essentials - M21 - Exception Handling
Python Programming Essentials - M20 - Classes and Objects
Python Programming Essentials - M20 - Classes and Objects
Python Programming Essentials - M19 - Namespaces, Global Variables and Docstr...
Python Programming Essentials - M19 - Namespaces, Global Variables and Docstr...
Python Programming Essentials - M18 - Modules and Packages
Python Programming Essentials - M18 - Modules and Packages
Python Programming Essentials - M15 - References
Python Programming Essentials - M15 - References
Python Programming Essentials - M14 - Dictionaries
Python Programming Essentials - M14 - Dictionaries
Python Programming Essentials - M13 - Tuples
Python Programming Essentials - M13 - Tuples
Python Programming Essentials - M12 - Lists
Python Programming Essentials - M12 - Lists
Python Programming Essentials - M11 - Comparison and Logical Operators
Python Programming Essentials - M11 - Comparison and Logical Operators
Python Programming Essentials - M10 - Numbers and Artihmetic Operators
Python Programming Essentials - M10 - Numbers and Artihmetic Operators
Python Programming Essentials - M9 - String Formatting
Python Programming Essentials - M9 - String Formatting
Python Programming Essentials - M8 - String Methods
Python Programming Essentials - M8 - String Methods
Python Programming Essentials - M7 - Strings
Python Programming Essentials - M7 - Strings
Python Programming Essentials - M6 - Code Blocks and Indentation
Python Programming Essentials - M6 - Code Blocks and Indentation
Python Programming Essentials - M34 - List Comprehensions
1.
http://www.skillbrew.com /Skillbrew Talent brewed by
the industry itself List Comprehensions Pavan Verma @YinYangPavan Founder, P3 InfoTech Solutions Pvt. Ltd. 1 Python Programming Essentials
2.
© SkillBrew http://skillbrew.com Contents
Introduction Syntax filter Nested loops 2
3.
© SkillBrew http://skillbrew.com Introduction Lets
say you are given a list and your task is to generate another list of cubes sample = [10, 20, 30, 40] cubes = [] for x in sample: cubes.append(x**3) print cubes Output: [1000, 8000, 27000, 64000] 3
4.
© SkillBrew http://skillbrew.com Lets
write a List comprehension sample = [10, 20, 30, 40] cubes = [ x**3 for x in sample_list] print cubes Output: [1000, 8000, 27000, 64000] 4 sample = [10, 20, 30, 40] cubes = [] for x in sample: cubes.append(x**3) vs
5.
© SkillBrew http://skillbrew.com Syntax cubes
= [ x**3 for x in sample_list] Expression For loop 5
6.
© SkillBrew http://skillbrew.com Filter Lets
tweak the problem a little. Generate a list of cubes but do the operation only on elements that are even. sample = [10, 21, 33, 40] cubes = [ x**3 for x in sample if x%2 == 0 ] print cubes Output: [1000, 64000] 6
7.
© SkillBrew http://skillbrew.com Nested
for loops Lets say you have a 3 3 Matrix and you have to print out all the coordinate pairs 0 1 2 0 (0,0) (0, 1) (0, 2) 1 (1,0) (1, 1) (1, 2) 2 (2,0) (2, 1) (2, 2) 7
8.
© SkillBrew http://skillbrew.com Naive
way matrix = [] for x in range(3): for y in range(3): matrix.append((x,y)) print matrix Output: [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)] 8
9.
© SkillBrew http://skillbrew.com With
List comprehensions matrix = [(x,y) for x in range(3) for y in range(3)] print matrix Output: [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)] 9
10.
© SkillBrew http://skillbrew.com Takeaways 1.
You have to write less code 2. Keeps the code clean as the syntax is precise and a one-liner 10
11.
© SkillBrew http://skillbrew.com Resources
http://www.pythonforbeginners.com/list s/list-comprehensions-in-python/ 11
12.
12