This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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. | |
******************************************** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#sb1 { | |
width:400px; | |
height:400px; | |
display:inline-block; | |
border: 3px solid lime; | |
word-wrap:break-word; | |
overflow-x:scroll; | |
overflow-y:scroll; | |
} | |
p { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
OlderNewer