Skip to content

Instantly share code, notes, and snippets.

# The Gist discusses on how to create a simple dictonary in Python.
nato_alphabet={
"A":"Alpha",
"B":"Beta",
"C":"Charlie",
"D":"Delta",
"E":"Echo",
"F":"Foxtrot",
"G":"Golf",
"H":"Hotel",
@venkatsgithub1
venkatsgithub1 / popFromList.py
Created April 15, 2017 16:53
Python | Removal of data from a list using pop method.
#Usage of pop method to remove elements from list.
def print_popped_element (element):
print ("%s is popped out from list" %element)
list_of_items=["Watch", "Headphones", "Mobile Phone", "Laptop"]
"""
********************************************
Pop out from list using index.
********************************************
@venkatsgithub1
venkatsgithub1 / removeFromList.py
Last active April 15, 2017 17:00
Python | Removal of data from list using remove method.
#Usage of remove method to remove elements from list.
list_of_items=["Watch", "Headphones", "Mobile Phone", "Laptop"]
"""
******************************
remove method removes the
actual element passed
from the list.
Data passed into remove method
@venkatsgithub1
venkatsgithub1 / delFromList.py
Created April 15, 2017 17:05
Python | Using del function to remove data from list.
#Usage of delete method to remove elements from list.
list_of_items=["Watch", "Headphones", "Mobile Phone", "Laptop"]
"""
*****************************
delete method takes element
in the following format:
del (list[n])
where list is the name of the
list, n is the index of the
@venkatsgithub1
venkatsgithub1 / ParallelScroll.css
Last active August 12, 2023 18:02
Small Demo on creation of Parallel Scrolls in two Div elements.
#sb1 {
width:400px;
height:400px;
display:inline-block;
border: 3px solid lime;
word-wrap:break-word;
overflow-x:scroll;
overflow-y:scroll;
}
p {
@venkatsgithub1
venkatsgithub1 / PyExcp1.py
Created June 11, 2017 05:19
Basic Exception Handling in Python
def enterANumber ():
number=int(input ("Enter a number"))
print (number/2)
"""
Under try we write code.
Under except errors are handled.
In this example, user may enter
non numeric inputs which may
@venkatsgithub1
venkatsgithub1 / DiceRoll.py
Created June 11, 2017 06:14
Dice Roll Simulator
import random
roll_low = 1
roll_high = 6
roll_again = 'Yes'
while roll_again.lower() == 'yes' or roll_again.lower() == 'y':
print("Dice Simulation started...")
print("Result of roll", random.randint(roll_low, roll_high), random.randint(roll_low, roll_high))
@venkatsgithub1
venkatsgithub1 / CopyData.py
Created June 17, 2017 14:11
The Python code uses pyperclip module to get user data from clipboard.
import pyperclip,sys,json
from os import path
"""
To install pyperclip use the following command:
pip install pyperclip
The code takes description from runtime variables
using sys module and paste the clipboard information
into a json file as key value pairs.
key=description, value=data in clipboard.
@venkatsgithub1
venkatsgithub1 / quicksort_algo.py
Last active July 25, 2017 18:02
Quick sort algorithm in Python
def quicksort(templist):
if len(templist)<=1:
return templist
pivot=templist[0]
left,right=[],[]
for data in templist:
if data<pivot:
left.append(data)
elif data>pivot:
@venkatsgithub1
venkatsgithub1 / PersonClass_Simple.py
Created October 17, 2017 17:40
Creating a simple class in Python
class Person:
"""A simple class in Python"""
def __init__(self, name, age):
"""
The function __init__ is like a
constructor for the class.
"""
self.name = name
self.age = age