SlideShare a Scribd company logo
Examples in Python
 Python is a programming language with strengths of both functional and object-oriented 
programming. 
 Here I will present common problems and their solutions that you might use while 
starting coding in Python. 
 You may use this material as a reference. 
By Ashish Sharma for Next Craft
 One who has began learning Python. 
 One who has made oneself acquainted with concepts of Python taught in 
codecademy.com Python course. 
 One who wishes to learn the idioms of python to solve problems in pythonic way. 
 One who is interested in free, good content.  
By Ashish Sharma for Next Craft
 Learn by Doing: Here are examples of python code used in different scenarios. 
 You can try to pick the concepts and then mould them to use in your own 
situation. 
 Use of Classes, Exceptions, rest of Standard Library not covered here. 
By Ashish Sharma for Next Craft
 Let us suppose we have a file containing a student’s SGPAs from 8 semesters and 
we would like to write a new file with CGPA. 
 SGPA.txt , has list of numbers in different lines. 
 Generating CGPA.txt from SGPA.txt 
 We will first read the SGPA.txt file line by line, 
 Then accumulate the values into a single variable, 
 Then calculate CGPA value and write that back into a new file. 
Try out yourself with sample 
data 
By Ashish Sharma for Next Craft
Code 
By Ashish Sharma for Next Craft
 Let us suppose you have a list of SGPAs on scale of 10 and from it you want to 
calculate CGPA on scale of 4. 
 We will do this in two ways, 
 Using for loop, 
 Using map, reduce (they are not as scary as they may sound) 
 The ways of coding this by map, reduce etc. are less verbose and more 
transportable. 
By Ashish Sharma for Next Craft
Using for loop 
By Ashish Sharma for Next Craft
Using Reduce 
Using Map/Reduce 
By Ashish Sharma for Next Craft
 In Python the data structure of Map is implemented in Dictionary. 
 A map is a structure to store <key, value> relationships. 
 Suppose you need to compute sum of squares of given odd numbers that can not 
be smaller than 1 and larger than 99 
 In the example, we will pre compute as the limits are small and return answers 
from a dict. 
By Ashish Sharma for Next Craft
Code. 
By Ashish Sharma for Next Craft
 From the older sgpa example, if we wish to filter out the sgpa from list that were 
more than 8.5. 
 From the older odd_squares example, if we wish to filter out the odd squares 
where the number is a multiple of 3. 
By Ashish Sharma for Next Craft
 Here we will validate data sent our way with regular expressions. You can also use 
them for search, match and replace. 
 Suppose we want input from user to be a number, here is how to gracefully handle 
this requirement. 
By Ashish Sharma for Next Craft
 Unit testing is a very important aspect of software development. In Python, you 
can find extensive support for unit testing you code. 
 With unit testing we can test single functions, classes or whole modules. 
 Having code and test separately and testable is a prime software development 
requirement. 
 This fact is elicited in this advice that developers get from creator of Unit testing 
framework for Small talk, (one of the first or may be the first frameworks). 
 I recommend that developers spend 25-50% of their time developing tests. 
 Quoted from - http://www.xprogramming.com/testfram.htm 
By Ashish Sharma for Next Craft
 Here is a sample of code and test files. 
By Ashish Sharma for Next Craft
Please let me know in the comments if I am missing any general scenarios, which 
you would like to see in the examples here. 
I will be more than happy to extend this presentation. 
By Ashish Sharma for Next Craft
 Python Reference – The best guide on Python out there. 
 Codecademy – Beginner course on Python, totally free . 
 http://learnpythonthehardway.org/ - If you want to develop a deep sense of 
knowledge of Python, venture here. 
By Ashish Sharma for Next Craft
Find me at @ashish424242 and @kartaa. 
Checkout NextCraft’s JMP 
By Ashish Sharma for Next Craft
Ad

Recommended

KMP Pattern Search
KMP Pattern Search
Arjun SK
 
Logic programming in python
Logic programming in python
Pierre Carbonnelle
 
Init() Day 4
Init() Day 4
UCLA Association of Computing Machinery
 
Intro To BOOST.Spirit
Intro To BOOST.Spirit
Will Shen
 
Python tutorial
Python tutorial
Andrei Tomoroga
 
libpinyin
libpinyin
Peng Wu
 
Response to uspto on the first topic v5
Response to uspto on the first topic v5
getsocialize
 
Introduction to Structure Programming with C++
Introduction to Structure Programming with C++
Mohamed Essam
 
Lets learn Python !
Lets learn Python !
Kiran Gangadharan
 
Introduction to Python
Introduction to Python
Nowell Strite
 
Python 4 Arc
Python 4 Arc
absvis
 
The Python Programming Language and HDF5: H5Py
The Python Programming Language and HDF5: H5Py
The HDF-EOS Tools and Information Center
 
Python in real world.
Python in real world.
[email protected]
 
Substituting HDF5 tools with Python/H5py scripts
Substituting HDF5 tools with Python/H5py scripts
The HDF-EOS Tools and Information Center
 
Introduction To Programming with Python-1
Introduction To Programming with Python-1
Syed Farjad Zia Zaidi
 
Logic Over Language
Logic Over Language
Purple, Rock, Scissors
 
Python and HDF5: Overview
Python and HDF5: Overview
andrewcollette
 
An Introduction to Interactive Programming in Python 2013
An Introduction to Interactive Programming in Python 2013
Syed Farjad Zia Zaidi
 
Introduction to Databases
Introduction to Databases
Syed Farjad Zia Zaidi
 
Logic: Language and Information 1
Logic: Language and Information 1
Syed Farjad Zia Zaidi
 
Introduction To Programming with Python-5
Introduction To Programming with Python-5
Syed Farjad Zia Zaidi
 
Introduction To Programming with Python-4
Introduction To Programming with Python-4
Syed Farjad Zia Zaidi
 
Introduction to UBI
Introduction to UBI
Roy Lee
 
Clase 2 estatica
Clase 2 estatica
Gerald Moreira Ramírez
 
Python
Python
Purev-Oidov Gonchigsuren
 
Using HDF5 and Python: The H5py module
Using HDF5 and Python: The H5py module
The HDF-EOS Tools and Information Center
 
HDF5 Tools
HDF5 Tools
The HDF-EOS Tools and Information Center
 
Beginning Python
Beginning Python
Agiliq Info Solutions India Pvt Ltd
 
Python Part 1
Python Part 1
Mohamed Ramadan
 
Beginning Python
Beginning Python
Agiliq Solutions
 

More Related Content

Viewers also liked (19)

Lets learn Python !
Lets learn Python !
Kiran Gangadharan
 
Introduction to Python
Introduction to Python
Nowell Strite
 
Python 4 Arc
Python 4 Arc
absvis
 
The Python Programming Language and HDF5: H5Py
The Python Programming Language and HDF5: H5Py
The HDF-EOS Tools and Information Center
 
Python in real world.
Python in real world.
[email protected]
 
Substituting HDF5 tools with Python/H5py scripts
Substituting HDF5 tools with Python/H5py scripts
The HDF-EOS Tools and Information Center
 
Introduction To Programming with Python-1
Introduction To Programming with Python-1
Syed Farjad Zia Zaidi
 
Logic Over Language
Logic Over Language
Purple, Rock, Scissors
 
Python and HDF5: Overview
Python and HDF5: Overview
andrewcollette
 
An Introduction to Interactive Programming in Python 2013
An Introduction to Interactive Programming in Python 2013
Syed Farjad Zia Zaidi
 
Introduction to Databases
Introduction to Databases
Syed Farjad Zia Zaidi
 
Logic: Language and Information 1
Logic: Language and Information 1
Syed Farjad Zia Zaidi
 
Introduction To Programming with Python-5
Introduction To Programming with Python-5
Syed Farjad Zia Zaidi
 
Introduction To Programming with Python-4
Introduction To Programming with Python-4
Syed Farjad Zia Zaidi
 
Introduction to UBI
Introduction to UBI
Roy Lee
 
Clase 2 estatica
Clase 2 estatica
Gerald Moreira Ramírez
 
Python
Python
Purev-Oidov Gonchigsuren
 
Using HDF5 and Python: The H5py module
Using HDF5 and Python: The H5py module
The HDF-EOS Tools and Information Center
 
HDF5 Tools
HDF5 Tools
The HDF-EOS Tools and Information Center
 
Introduction to Python
Introduction to Python
Nowell Strite
 
Python 4 Arc
Python 4 Arc
absvis
 
Introduction To Programming with Python-1
Introduction To Programming with Python-1
Syed Farjad Zia Zaidi
 
Python and HDF5: Overview
Python and HDF5: Overview
andrewcollette
 
An Introduction to Interactive Programming in Python 2013
An Introduction to Interactive Programming in Python 2013
Syed Farjad Zia Zaidi
 
Introduction To Programming with Python-5
Introduction To Programming with Python-5
Syed Farjad Zia Zaidi
 
Introduction To Programming with Python-4
Introduction To Programming with Python-4
Syed Farjad Zia Zaidi
 
Introduction to UBI
Introduction to UBI
Roy Lee
 

Similar to Python programming - Everyday(ish) Examples (20)

Beginning Python
Beginning Python
Agiliq Info Solutions India Pvt Ltd
 
Python Part 1
Python Part 1
Mohamed Ramadan
 
Beginning Python
Beginning Python
Agiliq Solutions
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
Utkarsh Sengar
 
Introduction to python programming 1
Introduction to python programming 1
Giovanni Della Lunga
 
Introduction to Python For Diploma Students
Introduction to Python For Diploma Students
SanjaySampat1
 
Python basics
Python basics
Bladimir Eusebio Illanes Quispe
 
Introduction to Python
Introduction to Python
UC San Diego
 
1P13 Python Review Session Covering various Topics
1P13 Python Review Session Covering various Topics
hussainmuhd1119
 
Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1
Andrei KUCHARAVY
 
Data Structure and Algorithms (DSA) with Python
Data Structure and Algorithms (DSA) with Python
epsilonice
 
Talk Code
Talk Code
Agiliq Solutions
 
Learn python in 20 minutes
Learn python in 20 minutes
Sidharth Nadhan
 
An Introduction : Python
An Introduction : Python
Raghu Kumar
 
GE3151_PSPP_UNIT_5_Notes
GE3151_PSPP_UNIT_5_Notes
Guru Nanak Technical Institutions
 
A quick python_tour
A quick python_tour
cghtkh
 
ppt_pspp.pdf
ppt_pspp.pdf
ShereenAhmedMohamed
 
Python-languageinterview -Questions-A-Comprehensive-Guide.pptx
Python-languageinterview -Questions-A-Comprehensive-Guide.pptx
nathvansh89
 
Processing data with Python, using standard library modules you (probably) ne...
Processing data with Python, using standard library modules you (probably) ne...
gjcross
 
Python-content-1.pdf
Python-content-1.pdf
panimalarhemdochemla
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
Utkarsh Sengar
 
Introduction to python programming 1
Introduction to python programming 1
Giovanni Della Lunga
 
Introduction to Python For Diploma Students
Introduction to Python For Diploma Students
SanjaySampat1
 
Introduction to Python
Introduction to Python
UC San Diego
 
1P13 Python Review Session Covering various Topics
1P13 Python Review Session Covering various Topics
hussainmuhd1119
 
Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1
Andrei KUCHARAVY
 
Data Structure and Algorithms (DSA) with Python
Data Structure and Algorithms (DSA) with Python
epsilonice
 
Learn python in 20 minutes
Learn python in 20 minutes
Sidharth Nadhan
 
An Introduction : Python
An Introduction : Python
Raghu Kumar
 
A quick python_tour
A quick python_tour
cghtkh
 
Python-languageinterview -Questions-A-Comprehensive-Guide.pptx
Python-languageinterview -Questions-A-Comprehensive-Guide.pptx
nathvansh89
 
Processing data with Python, using standard library modules you (probably) ne...
Processing data with Python, using standard library modules you (probably) ne...
gjcross
 
Ad

Recently uploaded (20)

CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
Simplify Insurance Regulations with Compliance Management Software
Simplify Insurance Regulations with Compliance Management Software
Insurance Tech Services
 
Sap basis role in public cloud in s/4hana.pptx
Sap basis role in public cloud in s/4hana.pptx
htmlprogrammer987
 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
Y - Recursion The Hard Way GopherCon EU 2025
Y - Recursion The Hard Way GopherCon EU 2025
Eleanor McHugh
 
Sysinfo OST to PST Converter Infographic
Sysinfo OST to PST Converter Infographic
SysInfo Tools
 
Foundations of Marketo Engage - Programs, Campaigns & Beyond - June 2025
Foundations of Marketo Engage - Programs, Campaigns & Beyond - June 2025
BradBedford3
 
Azure AI Foundry: The AI app and agent factory
Azure AI Foundry: The AI app and agent factory
Maxim Salnikov
 
ERP Systems in the UAE: Driving Business Transformation with Smart Solutions
ERP Systems in the UAE: Driving Business Transformation with Smart Solutions
dheeodoo
 
Building Geospatial Data Warehouse for GIS by GIS with FME
Building Geospatial Data Warehouse for GIS by GIS with FME
Safe Software
 
Simplify Task, Team, and Project Management with Orangescrum Work
Simplify Task, Team, and Project Management with Orangescrum Work
Orangescrum
 
Humans vs AI Call Agents - Qcall.ai's Special Report
Humans vs AI Call Agents - Qcall.ai's Special Report
Udit Goenka
 
Zoho Creator Solution for EI by Elsner Technologies.docx
Zoho Creator Solution for EI by Elsner Technologies.docx
Elsner Technologies Pvt. Ltd.
 
Best AI-Powered Wearable Tech for Remote Health Monitoring in 2025
Best AI-Powered Wearable Tech for Remote Health Monitoring in 2025
SEOLIFT - SEO Company London
 
arctitecture application system design os dsa
arctitecture application system design os dsa
za241967
 
Advance Doctor Appointment Booking App With Online Payment
Advance Doctor Appointment Booking App With Online Payment
AxisTechnolabs
 
AI for PV: Development and Governance for a Regulated Industry
AI for PV: Development and Governance for a Regulated Industry
Biologit
 
Threat Modeling a Batch Job Framework - Teri Radichel - AWS re:Inforce 2025
Threat Modeling a Batch Job Framework - Teri Radichel - AWS re:Inforce 2025
2nd Sight Lab
 
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
pcprocore
 
OpenChain Webinar - AboutCode - Practical Compliance in One Stack – Licensing...
OpenChain Webinar - AboutCode - Practical Compliance in One Stack – Licensing...
Shane Coughlan
 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
Simplify Insurance Regulations with Compliance Management Software
Simplify Insurance Regulations with Compliance Management Software
Insurance Tech Services
 
Sap basis role in public cloud in s/4hana.pptx
Sap basis role in public cloud in s/4hana.pptx
htmlprogrammer987
 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
Y - Recursion The Hard Way GopherCon EU 2025
Y - Recursion The Hard Way GopherCon EU 2025
Eleanor McHugh
 
Sysinfo OST to PST Converter Infographic
Sysinfo OST to PST Converter Infographic
SysInfo Tools
 
Foundations of Marketo Engage - Programs, Campaigns & Beyond - June 2025
Foundations of Marketo Engage - Programs, Campaigns & Beyond - June 2025
BradBedford3
 
Azure AI Foundry: The AI app and agent factory
Azure AI Foundry: The AI app and agent factory
Maxim Salnikov
 
ERP Systems in the UAE: Driving Business Transformation with Smart Solutions
ERP Systems in the UAE: Driving Business Transformation with Smart Solutions
dheeodoo
 
Building Geospatial Data Warehouse for GIS by GIS with FME
Building Geospatial Data Warehouse for GIS by GIS with FME
Safe Software
 
Simplify Task, Team, and Project Management with Orangescrum Work
Simplify Task, Team, and Project Management with Orangescrum Work
Orangescrum
 
Humans vs AI Call Agents - Qcall.ai's Special Report
Humans vs AI Call Agents - Qcall.ai's Special Report
Udit Goenka
 
Zoho Creator Solution for EI by Elsner Technologies.docx
Zoho Creator Solution for EI by Elsner Technologies.docx
Elsner Technologies Pvt. Ltd.
 
Best AI-Powered Wearable Tech for Remote Health Monitoring in 2025
Best AI-Powered Wearable Tech for Remote Health Monitoring in 2025
SEOLIFT - SEO Company London
 
arctitecture application system design os dsa
arctitecture application system design os dsa
za241967
 
Advance Doctor Appointment Booking App With Online Payment
Advance Doctor Appointment Booking App With Online Payment
AxisTechnolabs
 
AI for PV: Development and Governance for a Regulated Industry
AI for PV: Development and Governance for a Regulated Industry
Biologit
 
Threat Modeling a Batch Job Framework - Teri Radichel - AWS re:Inforce 2025
Threat Modeling a Batch Job Framework - Teri Radichel - AWS re:Inforce 2025
2nd Sight Lab
 
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
pcprocore
 
OpenChain Webinar - AboutCode - Practical Compliance in One Stack – Licensing...
OpenChain Webinar - AboutCode - Practical Compliance in One Stack – Licensing...
Shane Coughlan
 
Ad

Python programming - Everyday(ish) Examples

  • 2.  Python is a programming language with strengths of both functional and object-oriented programming.  Here I will present common problems and their solutions that you might use while starting coding in Python.  You may use this material as a reference. By Ashish Sharma for Next Craft
  • 3.  One who has began learning Python.  One who has made oneself acquainted with concepts of Python taught in codecademy.com Python course.  One who wishes to learn the idioms of python to solve problems in pythonic way.  One who is interested in free, good content.  By Ashish Sharma for Next Craft
  • 4.  Learn by Doing: Here are examples of python code used in different scenarios.  You can try to pick the concepts and then mould them to use in your own situation.  Use of Classes, Exceptions, rest of Standard Library not covered here. By Ashish Sharma for Next Craft
  • 5.  Let us suppose we have a file containing a student’s SGPAs from 8 semesters and we would like to write a new file with CGPA.  SGPA.txt , has list of numbers in different lines.  Generating CGPA.txt from SGPA.txt  We will first read the SGPA.txt file line by line,  Then accumulate the values into a single variable,  Then calculate CGPA value and write that back into a new file. Try out yourself with sample data By Ashish Sharma for Next Craft
  • 6. Code By Ashish Sharma for Next Craft
  • 7.  Let us suppose you have a list of SGPAs on scale of 10 and from it you want to calculate CGPA on scale of 4.  We will do this in two ways,  Using for loop,  Using map, reduce (they are not as scary as they may sound)  The ways of coding this by map, reduce etc. are less verbose and more transportable. By Ashish Sharma for Next Craft
  • 8. Using for loop By Ashish Sharma for Next Craft
  • 9. Using Reduce Using Map/Reduce By Ashish Sharma for Next Craft
  • 10.  In Python the data structure of Map is implemented in Dictionary.  A map is a structure to store <key, value> relationships.  Suppose you need to compute sum of squares of given odd numbers that can not be smaller than 1 and larger than 99  In the example, we will pre compute as the limits are small and return answers from a dict. By Ashish Sharma for Next Craft
  • 11. Code. By Ashish Sharma for Next Craft
  • 12.  From the older sgpa example, if we wish to filter out the sgpa from list that were more than 8.5.  From the older odd_squares example, if we wish to filter out the odd squares where the number is a multiple of 3. By Ashish Sharma for Next Craft
  • 13.  Here we will validate data sent our way with regular expressions. You can also use them for search, match and replace.  Suppose we want input from user to be a number, here is how to gracefully handle this requirement. By Ashish Sharma for Next Craft
  • 14.  Unit testing is a very important aspect of software development. In Python, you can find extensive support for unit testing you code.  With unit testing we can test single functions, classes or whole modules.  Having code and test separately and testable is a prime software development requirement.  This fact is elicited in this advice that developers get from creator of Unit testing framework for Small talk, (one of the first or may be the first frameworks).  I recommend that developers spend 25-50% of their time developing tests.  Quoted from - http://www.xprogramming.com/testfram.htm By Ashish Sharma for Next Craft
  • 15.  Here is a sample of code and test files. By Ashish Sharma for Next Craft
  • 16. Please let me know in the comments if I am missing any general scenarios, which you would like to see in the examples here. I will be more than happy to extend this presentation. By Ashish Sharma for Next Craft
  • 17.  Python Reference – The best guide on Python out there.  Codecademy – Beginner course on Python, totally free .  http://learnpythonthehardway.org/ - If you want to develop a deep sense of knowledge of Python, venture here. By Ashish Sharma for Next Craft
  • 18. Find me at @ashish424242 and @kartaa. Checkout NextCraft’s JMP By Ashish Sharma for Next Craft