Skip to content

Instantly share code, notes, and snippets.

@akilawickey
Created July 10, 2016 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akilawickey/83136f44713304dc9097d69dd6abfd8a to your computer and use it in GitHub Desktop.
Save akilawickey/83136f44713304dc9097d69dd6abfd8a to your computer and use it in GitHub Desktop.
This is a codebank with python
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="projectConfiguration" value="py.test" />
<option name="PROJECT_TEST_RUNNER" value="py.test" />
</component>
</module>
<component name="InspectionProjectProfileManager">
<settings>
<option name="PROJECT_PROFILE" value="Project Default" />
<option name="USE_PROJECT_PROFILE" value="true" />
<version value="1.0" />
</settings>
</component>
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyCompatibilityInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ourVersions">
<value>
<list size="2">
<item index="0" class="java.lang.String" itemvalue="2.7" />
<item index="1" class="java.lang.String" itemvalue="3.5" />
</list>
</value>
</option>
</inspection_tool>
</profile>
</component>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 2.7.6 (/usr/bin/python2.7)" project-jdk-type="Python SDK" />
<component name="PythonCompatibilityInspectionAdvertiser">
<option name="version" value="1" />
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/coders.iml" filepath="$PROJECT_DIR$/.idea/coders.iml" />
</modules>
</component>
</project>
import sys
def fact(n):
"""
Factorial function
:arg n: Number
:returns: factorial of n
"""
if n == 0:
return 1
return n * fact(n -1)
def div(n):
"""
Just divide
"""
res = 10 / n
return res
def main(n):
res = fact(n)
print(res)
if __name__ == '__main__':
if len(sys.argv) > 1:
main(int(sys.argv[1]))
from __future__ import print_function
# strings = ['I', 'am', 'the', 'laziest', 'person', 'in', 'the', 'world' ]
# s = ''
# for a in strings:
# s = s + a + ' '
# print s
#
#
# l = range(5)
# print l
# print l[2:4]
# print l[2:]
# print l[:4]
# print l[:]
#
#
# first = raw_input()
# second = raw_input()
#
# print('Hello '+first+' you just delved into python.')
# while True:
# value = raw_input('Enter a value: ')
# value = value.strip()
# if value == 'quit': break
import sys
# N = int(raw_input().strip())
#
# if N % 2 == 0:
# if ((N > 2) & (N < 5)):
# print('Not Weird')
# elif((N > 6) & (N < 20)):
# print('Weird')
# elif (N > 20):
# print('Not Weird')
# else:
# print('Weird')
#
# num1 = raw_input()
# num2 = raw_input()
#
# add = num1 + num2
# sub = num1 - num2
# mul = num1 * num2
#
# print(add)
# print(sub)
# print(mul)
# num1 = int(raw_input().strip())
# num2 = int(raw_input().strip())
#
# div = num1 // num2
# div2 = num1/num2
#
# print(div)
# print(div2)
# N = int(raw_input().strip())
# l = range(1,N+1)
# l[1:N+1]
# result = list(map(int,l))
# ans = ' '.join(result)
# print(ans)
# import sys
# N = raw_input()
# L = []
# L.append(N)
#
# command = []
# command.append(raw_input())
# arr = []
# for i in range(int(raw_input())):
# s = raw_input().split()
# for i in range(1, len(s)):
# s[i] = int(s[i])
#
# if s[0] == "append":
# arr.append(s[1])
# elif s[0] == "extend":
# arr.extend(s[1:])
# elif s[0] == "insert":
# arr.insert(s[1], s[2])
# elif s[0] == "remove":
# arr.remove(s[1])
# elif s[0] == "pop":
# arr.pop()
# elif s[0] == "index":
# print
# arr.index(s[1])
# elif s[0] == "count":
# print
# arr.count(s[1])
# elif s[0] == "sort":
# arr.sort()
# elif s[0] == "reverse":
# arr.reverse()
# elif s[0] == "print":
# print(arr)
#get inputs in seperate lines
# arr = []
# for i in range(int(raw_input())):
# s = raw_input().split()
#print(len(s))
for i in range(1,input()): #More than 2 lines will result in 0 score. Do not leave a blank line also
for i in range(1, i):
print(i, end='')
import math
class Solver:
def demo(self, a, b, c):
d = b ** 2 - 4 * a * c
if d >= 0:
disc = math.sqrt(d)
root1 = (-b + disc) / (2 * a)
root2 = (-b - disc) / (2 * a)
print(root1, root2)
else:
raise Exception
Solver().demo(2, 1, 0)
import unittest
from facorial import fact
class TestFactorial(unittest.TestCase):
"""
Our basic test class
"""
def test_fact(self):
"""
The actual test.
Any method which starts with ``test_`` will considered as a test case.
"""
res = fact(5)
self.assertEqual(res, 120)
if __name__ == '__main__':
unittest.main()
from unittest import TestCase
from solver import Solver
class TestSolver(TestCase):
def test_negative_discr(self):
s = Solver()
self.assertRaises(Exception, s.demo, 2, 1, 0)
def test_demo(self):
self.fail()
import unittest
def fun(x):
return x + 1
class MyTest(unittest.TestCase):
def test(self):
self.assertEqual(fun(3), 94)
import os
import math
os.system('cls')
os.system('')
os.system('color a')
os.system('title Quadratic Equation Solver')
#This is used for presentation of the function for WINDOWS cmd
#------------------------------------------------
def QuadSolve():
os.system('cls')
print(" Quadratic Equation Solver 1")
print("")
print(" X = (-b +/- sqrtb^2 + sqrt4ac)/div/2a ")
print("")
print(" Quadratic equation: ax^2 + bx + c")
print("")
print("")
print("")
a = int(input(" What is the value of a? ---> "))
b = int(input(" What is the value of b? ---> "))
c = int(input(" What is the value of c? ---> "))
firstsec = -1 * b #first second and third "sectors" of the expression
secsec = math.sqrt(b ** 2 - 4 * a * c)
thirdsec = 2 * a
Plussl = firstsec + secsec #Pluss1 is where -b and root b^2 + 4ac are added to give a value of X
X = Plussl / thirdsec
Negsl = firstsec - secsec #Same purpose as Plussl but subtraction is used instead to give the other solution of X
X2 = Negsl / thirdsec
print("")1
print(" X=%d OR X=%d ") % (X, X2)
os.system('pause >nul')
QuadSolve()
QuadSolve()
from operator import itemgetter
test = int(input())
f = open('output.txt','w')
for z in range(test):
people = int(input())
plist = []
for o in range(people):
name = input()
k = []
namelist = list(name.replace(' ',''))
namelist = set(namelist)
k.append(name)
k.append(len(namelist))
plist.append(k)
plist.sort(key=lambda t: t[0])
plist.sort(key=lambda t: t[1], reverse=True)
#print(plist)
print('Case #'+str(z+1)+': '+str(plist[0][0]) )
f.write('Case #'+str(z+1)+': '+str(plist[0][0]))
f.write('\n')
f.close()
from itertools import groupby
f = open('output.txt','w')
for i in range(int(raw_input())):
mylist=[]
a=[]
k = 0
max = 0
for j in range(int(raw_input())):
b = raw_input().strip()
n = b
n = n.replace(" ","")
a.append(''.join(k for k, g in groupby(sorted(n))))
a.sort()
c=[]
c.append(b)
c.append(len(a[k]))
#print(c)
k = k+1
mylist.append(c)
mylist.sort(key=lambda t:t[0] )
mylist.sort(key=lambda t: t[1], reverse=True)
print('Case #'+str(i+1)+': '+str(mylist[0][0]) )
f.write('Case #'+str(i+1)+': '+str(mylist[0][0]))
f.close()
Case #1: JOHNSONCase #2: A AB C
n = int(raw_input())
a = bin(n)[2:].zfill(32)
backwards = a[::-1]
b = int(backwards, 2)
print(b)
order = ' etaoinrshdlcumwf'
input = raw_input()
text = raw_input()
index = dict([ (y,x) for (x,y) in enumerate(order) ])
output = sorted(input, cmp=lambda x,y: index[x] - index[y])
print(output)
from collections import Counter
key = raw_input()
decrypted_text = raw_input()
i=0
b = [' ','e','t','a','o','i','n','r','s','h','d','l','c','u','m','w','f']
print(key[2])
print(b[1])
arr = []
s = []
for i in range(int(raw_input())):
s = raw_input().split()
num_of_pis = raw_input()
a=map(int,raw_input().split())
b=map(int,raw_input().split())
k = 0
for i in b:
if i == 0:
a[i+1] = 0
k = num_of_pis - (i+1)
print(a)
from collections import Counter
key = raw_input()
decrypted_text = raw_input()
i = 0
a = [10]
b = [10]
j = 0
while (i<30):
a = Counter(decrypted_text).most_common(i+1)[i]
print(a)
#print(a[0])
# if(j<10):
# if (j == 0):
# print (decrypted_text.replace(a[0], 'e'))
# if (j == 1):
# print (decrypted_text.replace(a[0], 't'))
# if (j == 2):
# print (decrypted_text.replace(a[0], 'a'))
# if (j == 3):
# print (decrypted_text.replace(a[0], 'o'))
# if (j == 4):
# print (decrypted_text.replace(a[0], 'i'))
# if (j == 5):
# print (decrypted_text.replace(a[0], 'n'))
# if (j == 6):
# print (decrypted_text.replace(a[0], 'r'))
# if (j == 7):
# print (decrypted_text.replace(a[0], 's'))
# if (j == 8):
# print (decrypted_text.replace(a[0], 'h'))
#
# j = j + 1
i = i+1
#print (decrypted_text.replace(' ', 'e'))
#print(a[0])
import random
import sys
import os
#print("Hello world")
quote = "\"Always remember this"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment