Skip to content

Instantly share code, notes, and snippets.

Avatar

Shrijan Aryal shreezan123

View GitHub Profile
View ShoppingList.py
class ShoppingList:
cart = {}
def __init__(self):
pass
def add_item(self,name,price):
self.cart[name] = price
def remove_item(self,name):
if name in self.cart:
View Incrementor.py
class Incrementor:
array = []
value = 0
arrayVals = []
def __init__(self,array):
self.array = array
def add_value(self,value):
self.value = value
def add_values(self,valuesArr):
self.arrayVals = valuesArr
View FoodCalculator.py
class FoodCalculator:
current_price = 0
def __init__(self):
pass
def add_item(self,value):
self.current_price = value #assign to instance variable
def get_tax(self,tax_rate):
return self.current_price*(tax_rate*0.01)
def get_tip(self,taxP,tipP):
after_tax = self.current_price+(0.01*taxP*self.current_price)
View library.py
class Library:
d1 = {}
def __init__(self):
pass
def add_book(self,book):
self.d1[book] = True
def check_out_book(self,book):
if book in self.d1:
del(self.d1[book])
@shreezan123
shreezan123 / TwoStacksQueue.py
Created Mar 6, 2018
Implement a queue using two stacks
View TwoStacksQueue.py
class QueueUsingStacks:
def __init__(self):
self.stack1 = []
self.stack2 = []
def enqueue(self,value):
self.stack1.append(value)
#if empty, pop from stack1 and put each value in stack2.
def dequeue(self):
@shreezan123
shreezan123 / DataCenter.java
Created Jun 18, 2017
Take input from txt file and perform respective job in the tree
View DataCenter.java
package lab5;
import java.util.Scanner;
public class DataCenterOrders {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int numOperations = in.nextInt();
// create object of BinarySearchTree class
BinarySearchTree tree1 = new BinarySearchTree();
@shreezan123
shreezan123 / BSTimplementation.java
Created Jun 18, 2017
BST implementation. To keep all the classes under a same class file, I have commented out the main function
View BSTimplementation.java
package lab5;
import java.util.ArrayList;
public class BinarySearchTree {
public class Node {
public int data;
public Node left;
public Node right;
/*
* Constructor if in which a value is passed, a Node
@shreezan123
shreezan123 / SortByFrequency.py
Created Feb 27, 2017
Sorting items in the list by the number of occurences
View SortByFrequency.py
def SortByFrequency(list1):
d1 = {}
list2 = []
for items in list1:
d1[items] = list1.count(items)
for thekeys in d1:
for i in range(0,d1[thekeys]):
list2.append(thekeys)
return list2
@shreezan123
shreezan123 / indexquestion.py
Created Feb 26, 2017
A confusion related to index of for loop.
View indexquestion.py
'''The code is meant to skip adding the character "a" and any other character that comes after "a". For this, I check if string's [i th] index = a, and add 1 to index, so that new index will be able to skip the character coming after "a". But this does not seem to be happening. Why is it so ?'''
str1 = "abcde"
str2 = ""
for i in range(len(str1)):
if str1[i] == "a":
i +=1
continue
else:
str2 += str1[i]
@shreezan123
shreezan123 / indexquestion.py
Created Feb 26, 2017
A confusion related to index of for loop.
View indexquestion.py
'''The code is meant to skip adding the character "a" and any other character that comes after "a". For this, I check if string's [i th] index = a, and add 1 to index, so that new index will be able to skip the character coming after "a". But this does not seem to be happening. Why is it so ?'''
str1 = "abcde"
str2 = ""
for i in range(len(str1)):
if str1[i] == "a":
i +=1
continue
else:
str2 += str1[i]
You can’t perform that action at this time.