Python Programs

17
Jun

Top 20 Open Source Python Libraries

Below is a list of the top 20 Open Source Libraries. Note that the list is neither exhaustive or stagnant. In a strong community as that Python has, the list is prone to change. The list has been prepared on the basis of popularity, no of users, python community feedback etc. The 20 below does not fall in any specific order and arrangement is quite random.

At the end of the day, it’s not which library you use. It’s how well you get the job done.

So here goes the list!

Zappa

Zappa is a system for running “serverless” Python web applications using AWS Lambda and AWS API Gateway. It handles all of the configuration and deployment automatically . Now it is easy to deploy an infinitely scalable application to the cloud with a just single command at the least possible cost often just a small fraction of the cost of a traditional web server.

OpenCV

OpenCV is a cross-platform library using which we can develop real-time computer vision applications.Originally developed by Intel, it was later supported by Willow Garage and is now maintained by Itseez.It  was built to provide a common infrastructure for computer vision applications and to accelerate the use of machine perception in the commercial products. Being a BSD-licensed product, OpenCV makes it easy for businesses to utilize and modify the code.

Django

Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. When you’re building a website, you always need a similar set of components: a way to handle user authentication (signing up, signing in, signing out), a management panel for your website, forms, a way to upload files, etc. Django takes care of the repetitive work for you so that you don’t have to reinvent the wheel all over again.

BeautifulSoup

Beautiful Soup is a Python library for pulling data out of HTML and XML files. It works with your favorite parser to provide idiomatic ways of navigating, searching, and modifying the parse tree. It is an incredible tool for pulling out information from a webpage. You can use it to extract tables, lists, paragraph and you can also put filters to extract information from web page.

TensorFlow

TensorFlow is an open source software library for machine learning across a range of tasks, and developed by Google to meet their needs for systems capable of building and training neural networks to detect and decipher patterns and correlations, analogous to the learning and reasoning which humans use. Checkout SQL cheatsheet by clicking here

NLTK

NLTK is a leading platform for building Python programs to work with human language data. It provides easy-to-use interfaces to over 50 corpora and lexical resources such as WordNet, along with a suite of text processing libraries for classification, tokenization, stemming, tagging, parsing, and semantic reasoning, wrappers for industrial-strength NLP libraries, and an active discussion forum.

Requests

Requests is an elegant and simple Apache2 licensed  HTTP library for PythonIt is designed to be used by humans to interact with the language. This means you don’t have to manually add query strings to URLs, or form-encode your POST data.

Numpy

NumPy is the fundamental package for scientific computing with Python. It contains a powerful N-dimensional array object,sophisticated (broadcasting) functions,tools for integrating C/C++ and Fortran code,useful linear algebra, Fourier transform, and random number capabilities and much more. The handy tool for any scientific computing.

Flask

Flask is a  BSD licensed microframework for Python based on Werkzeug, Jinja 2 and good intentions. With simplified and easy to write and maintain code, flask has certainly won a lot of hearts.

SQLAlchemy

SQLAlchemy is an open-source Python Database toolkit, which is also an ORM Mapper.It  allows you to write easy to read programs and  remove the necessity of writing tedious and error-prone raw SQL statements. Checkout SQL cheatsheet by clicking here

Pandas

Pandas is a Python package providing fast, flexible, and expressive data structures designed to make working with “relational” or “labeled” data both easy and intuitive. It aims to be the fundamental high-level building block for doing practical, real world data analysis in Python. Checkout Pandas cheatsheet by clicking here

Cryptography

Cryptography is a method of storing and transmitting data in a particular form so that only those for whom it is intended can read and process it. It  has become a highly important function in the modern world where security of data means everything.Cryptography is an actively developed library in python that provides cryptographic recipes and primitives.It  is divided into two layers of recipes and hazardous materials (hazmat) catering it’s best to your various cryptographic needs.

Scrapy

Scrapy is an open source and collaborative framework for extracting the data you need from websites in a fast, simple, yet extensible way.Comparing with Beautiful Soup, you need to provide a specific url, and Beautiful Soup will help you get the data from that page. You can give Scrapy a start url, and it will go on, crawling and extracting data, without having to explicitly give it every single URL.Also scrapy is a website scraping tool that uses Python, because Scrapy can crawl the contents of your webpage prior to extracting

Marshmallow

Marshmallow is a lightweight library for converting complex datatypes to and from native Python datatypes.It is an ORM/ODM/framework-agnostic library for converting complex datatypes, such as objects, to and from native Python datatypes.

Arrow

Arrow is a Python library that offers a sensible, human-friendly approach to creating, manipulating, formatting and converting dates, times, and timestamps. It implements and updates the datetime type, plugging gaps in functionality, and provides an intelligent module API that supports many common creation scenarios. Simply put, it helps you work with dates and times with fewer imports and a lot less code.

Matplotlib

Matplotlib is a Python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms. Matplotlib can be used in Python scripts, the Python and IPython shell, the jupyter notebook, web application servers, and four graphical user interface toolkits. Checkout Matplotlib cheatsheet by clicking here

Pillow

The pillow is one of the core libraries for image manipulation in Python. Now there’s an actively developed fork of PIL called Pillow  which is making quite a good round in the python community.

Bokeh

Bokeh is a Python interactive visualization library that targets modern web browsers for presentation. It’s goal is to provide elegant, concise construction of novel graphics in the style of D3.js, and to extend this capability with high-performance interactivity over very large or streaming datasets.

CSV

The easy to handle python library for all your CSV needs.CSV stands for Comma Separated Variables.They are like incredibly simplified spreadsheets whose contents are just plain text. Python’s CSV library makes working with them extremly simplified.

Milk

Milk is a machine learning toolkit for python. It’s focus is on supervised classification.Several classifiers available:SVMs (based on libsvm), k-NN, random forests, decision trees. It also performs
feature selection.

There are a lot more amazing libraries in Python that would come of as as a huge boon such as Asyncpg, urllib2,Theano,Tkinder, Pycrypto, Pygame etc. Want to add more to this list. Comment your suggestion below. We love hearing from you!

9
Jul

Encrypt Text

Question:

Write a Program to encrypt text by replacing each character by it’s successor.

Program:

Output:
Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

Addition Using Magic Methods

Question:

Using Magic Methods, overload the + operator so that length of varying units can be added. 

Program:

Explanation:

What are magic methods? They’re everything in object-oriented Python. They’re special methods that you can define to add “magic” to your classes, that is you won’t have to call them manually. They are called automatically behind the scenes.

Output:

Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

Sum of Natural Numbers Using Recursion

Question:

Write a python program to find sum of natural numbers using recursion

Program:

Explanation:

A recursive function (DEF) is a function which either calls itself or is in a potential cycle of function calls.

Output:

Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

Print ASCII Character

Question:

Write a python program to find ASCII character of a variable

Program:

Explanation:

ASCII (American Standard Code for Information Interchange) is the most common format for text files in computers and on the Internet. In an ASCII file, each alphabetic, numeric, or special character is represented with a 7-bit binary number (a string of seven 0s or 1s). 128 possible characters are defined.

Output:

Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

Divisibility of 13 Using Lambda

Question:

Use anonymous and filter functions and print a list of numbers divisible by 13 from the list [79, 65, 54, 39, 555, 339,623,]

Program:

Explanation:

The lambda operator or lambda function is a way to create small anonymous functions, i.e. functions without a name. These functions are throw-away functions, i.e. they are just needed where they have been created. Lambda functions are mainly used in combination with the functions filter(), map() and reduce().

Output:

Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

Iterators for xrange()

Question:

Write a iterator function to work like xrange()

Program:

Explanation:

The iterator protocol consists of two methods. The __iter__() method, which must return the iterator object and the next() method, which returns the next element from a sequence. Python has several built-in objects, which implement the iterator protocol. For example lists, tuples, strings, dictionaries or files.

Output:

 

9
Jul

Find Lines in Multiple Files

Question:

Write a python program to print only those lines in a list of files that has a particular word

Here, I am looking for a word ‘print’ in a list of python files.

Program:

Explanation:

Generator Expressions are generator version of list comprehensions. They look like list comprehensions, but returns a generator back instead of a list.

Output:

Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

Trace All Calls To A Function

Question:

Write a program to trace all calls to the below function

Program:
Output:
Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here

 

9
Jul

Multiples of 7 But Not 5

Question:

Write a python program which will find all such numbers which are divisible by 7 but are not a multiple of 5, between 1500 and 3000 (both included).

Program:

Output:
Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

Intersection of Two Sets

Question;

With two given lists ([6,5,6,2,2]) and ([9,5,6,7,9,2,7,0]), write a python program to make a list whose elements are intersection of the another list.

Program:

Explanation:

Use set() and “&=” to do set intersection operation.

Output:

Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

Python Program to Find Leap Year

Question:

Write a python program to find whether a given year is a leap year or not

Program:

Explanation:

A leap year is a calendar year containing one additional day added to keep the calendar year synchronized with the astronomical or seasonal year. 2016 is a leap year, which means that it has 366 days instead of the usual 365 days that an ordinary year has. An extra day is added in a leap year—February 29 —which is called an intercalary day or a leap day.

Output:

1.

2.
Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

Filter Even Numbers

Question:
Write a program which can filter even numbers in a list by using filter function. The list is: [11,12,13,14,15,16,17,18,19,20]. Use filter() to filter some elements in a list. Use lambda to define anonymous functions.

Program:

Explanation:

The function filter(function, list) offers an elegant way to filter out all the elements of a list for which the function function returns True.

The function filter(f,l) needs a function f as its first argument. f returns a Boolean value, i.e. either True or False. This function will be applied to every element of the list l. Only if f returns True, the element of the list be included in the result list.

Output:

Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

Power of 2

Question:

Display powers of two using anonymous function

Program:

Explanation:

The lambda operator or lambda function is a way to create small anonymous functions, i.e. functions without a name. These functions are throw-away functions, i.e. they are just needed where they have been created.

The general syntax of a lambda function is quite simple:
lambda argument_list: expression

The argument list consists of a comma separated list of arguments and the expression is an arithmetic expression using these arguments. You can assign the function to a variable to give it a name.

Output:

Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

Array Manipulation

Question:
Write a program which takes 2 digits, X,Y as input and generates a 2-dimensional array. The element value in the i-th row and j-th column of the array should be i*j.

Note: i=0,1…. X-1; j=0,1…,­Y-1.

Also input is in a comma-separated form.

Program:

Explanation:

Range function generates a list of numbers, which is generally used to iterate over with for loops.

Output:

Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

Binary Search

Question:

Write a program to sort the list  [58,6,78,12,333] using binary search and return index position of 12

Program:

Explanation:

Binary Search: Search a sorted array by repeatedly dividing the search interval in half. Begin with an interval covering the whole array. If the value of the search key is less than the item in the middle of the interval, narrow the interval to the lower half. Otherwise narrow it to the upper half. Repeatedly check until the value is found or the interval is empty.

Output:

Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

Compress Decompress Strings

Question:

Write a program to compress and decompress the string “Global SQA!Global SQA!Global SQA!Global SQA!Global SQA!Global SQA!”

Use zlib.compress() and zlib.decompress() to compress and decompress a string.

Program:

Explanation:

zlib.compressobj([level[, method[, wbits[, memlevel[, strategy]]]]])

Returns a compression object, to be used for compressing data streams that won’t fit into memory at once.

zlib.decompress(string[wbits[bufsize]])

Decompresses the data in string, returning a string containing the uncompressed data.

Output:

Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

Display Calender

Question:
Display calender using in-built functions

Program:

Explanation:

Module calendar is imported and the function month() is used to print the month calendar.

Output:

Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

Number of Letters and Digits

Question:
Write a program that accepts a sentence and calculate the number of letters and digits.

Program:

Explanation:

Function isdigit() checks whether the concerned character is a digit, while isalpha checks whether it is an alphabet

Output:

Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

Catch Exception

Question:
Write a function to compute 1 /0 and use try/except to catch the exceptions.

Program:

Explanation:

Even if a statement or expression is syntactically correct, it may cause an error when an attempt is made to execute it. Errors detected during execution are called exceptions and are not unconditionally fatal.

try statement may have more than one except clause, to specify handlers for different exceptions. At most one handler will be executed. Handlers only handle exceptions that occur in the corresponding try clause, not in other handlers of the same try statement. An except clause may name multiple exceptions as a parenthesized tuple.

Output:

Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here