http://www.codeskulptor.org/#user26_ZvPjz7GLuE8FuyP.py
# Mini-project #6 - Blackjack
import simplegui
import random
# load card sprite - 949x392 - source: jfitz.com
CARD_SIZE = (73, 98)
http://www.codeskulptor.org/#user26_ZvPjz7GLuE8FuyP.py
# Mini-project #6 - Blackjack
import simplegui
import random
# load card sprite - 949x392 - source: jfitz.com
CARD_SIZE = (73, 98)
from doctest import testmod | |
import math | |
def factorial(n): | |
"""Return the factorial of n, an exact integer >= 0. | |
If the result is small enough to fit in an int, return an int. | |
Else return a long. | |
>>> [factorial(n) for n in range(6)] |
# | |
# Implementation of the CHAR compression algorithm which corresponds to the literal "SASYZCRL". | |
def decompressCHAR(offset, page): | |
length = len(page) | |
resultByteArray = [] | |
currentResultArrayIndex = 0 | |
for currentByteIndex in range(length): | |
controlByte = page[offset+currentByteIndex] & 0xF0 |
import sqlite3 | |
import glob | |
import sas7bdat | |
class SASexport(sas7bdat.SAS7BDAT): | |
def head(self, n=5): | |
for i, row in enumerate(self.readData()): | |
print row | |
if i == n: | |
break |
# Test-driven development in Python for data analysis | |
import doctest, sys | |
def maxProduct(A): | |
""" A function to find the maximum value for a continuous subarray. | |
:param A: an array or list | |
:type A: lst | |
- testcase1 | |
>>> maxProduct([0, 2, 3,-2,4, 1, -1]) |
Function or method is the most basic unit in Python programming. Test-driven development is a key for a developer to assure the code quality of those units. In his book, Harry Percival illustrated a few great examples about how to use TDD with Python and Django. It seems that for web development, TDD including unit testing and integration testing is the cornerstone for every success. For data analysis, coding mostly relies on built-in packages instead large framework like Django, which makes TDD easier. In my opnion, TDD in data analysis could have three steps.
Step 1: requirement analysis
Before writing any code for data analysis, the programmer should seriously ask the customer or himself about the requirements.
what if the input data doesn't fit the assumptions?
string
object is immutable. An extra space has to be used to lower alphanumeric characters and squeeze others.
#-------------------------------------------------------------------------------
# Name: Valid Palindrome
# Purpose:
#
# Given a string, determine if it is a palindrome, considering only
# alphanumeric characters and ignoring cases.
#-------------------------------------------------------------------------------
# Name: Pascal's Triangle II
# Purpose:
#
# Given an index k, return the kth row of the Pascal's triangle.
#
# For example, given k = 3,
# Return [1,3,3,1].
yield
#-------------------------------------------------------------------------------
# Name: Generate Parentheses
# Purpose:
#
# Given n pairs of parentheses, write a function to
# generate all combinations of well-formed parentheses.
#
# For example, given n = 3, a solution set is: