Posts

Showing posts with the label python

How to Add / Append items to a list in Python

To add items to a list in python is a very general task that you might come across. Here we have an empty list that we are populating with 10 items using the append method. n = 10 list = [] for i in range(n): list.append(input()) print list That's it! Common Mistake its a common mistake of doing something like this n=10 list=[] for i in range(n): list[i]=input() this will throw an error IndexError: list assignment index out of range Because the list is empty and list[i] is trying to access index which does not exist!

Python Program for Binary Search with explanation

Binary search algorithm is used to find a number in a sorted list. so, the pre condition for binary search is that the list should be sorted. If the number is found then its index is returned. This algorithm works on divide and conquer principle. Read more »

Simple Hello World page with django 1.9 in Ubuntu / Linux Mint [Beginners] [Part - 2]

In the First part of this tutorial we created an app named helloworld and added it to the setting.py file. Now let's continue further towads our journey to make a 'Hello World' page with django. Read more »

Simple Hello World page with django 1.9 in Ubuntu / Linux Mint [Beginners] [Part - 1]

Django is a web framework written in python. It is good for fast web application development. In this tutorial we will learn how to make a simple web page showing "Hello World" using django templates. we will also be applying styling to our page with css static files, we won't be dealing with any database or any advanced stuffs here. This tutorial is aimed at beginners, So I 'll try to explain things in simple language without much technical detail. Read more »

Run Python SimpleHttpServer on Amazon AWS EC2

Image
With Python's SimpleHTTPServer you can quickly setup a webserver without any hassle. In order to use it, you don't need to install or configure anything.. you just need to have python installed on your server. Step 1: Open up your AWS console and in your instance security group make the Inbound & Outbound settings like shown in the sceenshots below Step 2: Login into your remote server via ssh example: aman@vostro:~$ ssh -i yourkeyfile.pem ubuntu@your-server-ip Read more »

Code Syntax Highlighting in django with Pygments

Image
Syntax Highlighting is a very much useful if you put code on your website. This can be easily achived with django-pygments . over 300 languages are supported. List of supported Languages:   http://pygments.org/languages/ django-pygments is the implementation of the pygments syntax highlighter for django. usage is quite simple. after setting up everything, you need to put necessary template tags and then place your code in pre tags with a lang attribute specifying the language of the source code in your template. example: <pre lang="python">YOUR CODE</pre> 1. First, Install the following packages. pip install pygments pip install django-pygments Read more »

How to make a gui Calculator in Python using Tkinter

Image
I have written a basic & simple GUI calculator in python using Tkinter module. Since Tkinter is cross-platform so it works on both windows and Linux . If you are a beginner, and want to learn some basic GUI with python, this will be helpful for you. you can download the program HERE    or, you can clone it from my github repository Read more »

How to install and use Tkinter in ubuntu / Debian / Linux mint

Tkinter is a GUI module for python. you can use it to make GUI based applications in python. Tkinter provides several GUI widgets like buttons,menu, canvas,text,frame,label etc. to develop desktop applications.Though Tkinter is very popular and is included with windows, macosx install of python, There are also alternative choices like pyQt, wxPython... Read more »