Skip to content

Instantly share code, notes, and snippets.

update promotion
set enddate = '2013-11-17'
where OFFERTYPE = '3FOR1' and
OFFERGROUP= 'ALLTESTERSGDB' and
site = 'EUKDLX'
my_file = open("output.txt", "r")
print my_file.read()
my_file.close()
my_list = [i**2 for i in range(1,11)]
f = open("output.txt", "w")
for item in my_list:
f.write(str(item) + "\n")
f.close()
@pgainda
pgainda / object_super.py
Created October 27, 2013 16:11
Sometimes you'll be working with a derived class (or subclass) and realize that you've overwritten a method or attribute defined in that class' base class (also called a parent or superclass) that you actually need. Have no fear! You can directly access the attributes or methods of a superclass with Python's built-in super call.
class Employee(object):
"""Models real-life employees!"""
def __init__(self, employee_name):
self.employee_name = employee_name
def calculate_wage(self, hours):
self.hours = hours
return hours * 20.00
# Add your code below!
class Animal(object):
is_alive = True
def __init__(self, name, age):
self.name = name
self.age = age
def description(self):
print self.name
print self.age
hippo = Animal("Jeffrey", 2)
class Animal(object):
def __init__(self, name):
self.name = name
zebra = Animal("Jeffrey")
print zebra.name
@pgainda
pgainda / list_slicing_strings.py
Created October 23, 2013 18:48
Crack the code...
garbled = "!XeXgXaXsXsXeXmX XtXeXrXcXeXsX XeXhXtX XmXaX XI"
message = filter(lambda x: x!="X" ,garbled[::-1])
languages = ["HTML", "JavaScript", "Python", "Ruby"]
#print python only
print filter(lambda x: x=="Python" ,languages)
@pgainda
pgainda / list_slice_negative.py
Created October 23, 2013 18:08
A positive stride progresses through the list from left to right; a negative stride progresses through the list from right to left.
my_list = range(1, 11)
# Add your code below!
backwards= my_list[::-1]
print backwards
@pgainda
pgainda / list_slice_indices.py
Created October 23, 2013 18:04
If you don't pass a particular index to the list slice, Python will pick a default. The default for the starting index is the first element of the list; the default for the ending index is the final element of the list; and the default for the stride index is 1.
my_list = range(1, 11) # List of numbers 1 - 10
#Every odd number
print my_list[::2]