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
# no copy | |
a = {1:'a', 2:'b', 3:{4:'c', 5:'d'}} | |
b = a | |
b[1] = 'lol' | |
print(a[1]) | |
b[3][4] = 'haha' | |
print(a[3][4]) | |
# shallow copy | |
c = {1:'a', 2:'b', 3:{4:'c', 5:'d'}} |
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 | |
import numpy as np | |
import numpy.linalg as la | |
import matplotlib.pyplot as plt | |
import time | |
import os | |
from math import * | |
from numpy import append, zeros | |
from scipy.io import wavfile |
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
a = 1 | |
def foo(): | |
print(a) # Prints 1. Accesses the variable a outside its own scope. | |
foo() | |
print(a) # Prints 1. a not modified. | |
b = 2 | |
def bar(): |
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
function parseVideo (url) { | |
// - Supported YouTube URL formats: | |
// - http://www.youtube.com/watch?v=My2FRPA3Gf8 | |
// - http://youtu.be/My2FRPA3Gf8 | |
// - https://youtube.googleapis.com/v/My2FRPA3Gf8 | |
// - Supported Vimeo URL formats: | |
// - http://vimeo.com/25451551 | |
// - http://player.vimeo.com/video/25451551 | |
// - Also supports relative URLs: | |
// - //player.vimeo.com/video/25451551 |
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
var fs = require('fs'); | |
var data = JSON.parse(fs.readFileSync('modules.json')); | |
var lessonTypes = ['DESIGN LECTURE', 'LABORATORY', 'LECTURE', 'PACKAGED LECTURE', | |
'PACKAGED TUTORIAL', 'RECITATION', 'SECTIONAL TEACHING', | |
'SEMINAR-STYLE MODULE CLASS', 'TUTORIAL', 'TUTORIAL TYPE 2', | |
'TUTORIAL TYPE 3']; | |
var weeks = ['EVERY WEEK', 'ODD WEEKS', 'EVEN WEEKS']; | |
var days = ['MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY']; |
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
# Replace section 1.1 of Assignment 3 with the following lines of code | |
# Final result looks something like this: http://imgur.com/nVCFDPh | |
def pts_set_2(): | |
def create_intermediate_points(pt1, pt2, granularity): | |
new_pts = [] | |
vector = np.array([(x[0] - x[1]) for x in zip(pt1, pt2)]) | |
return [(np.array(pt2) + (vector * (float(i)/granularity))) for i in range(1, granularity)] |
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
# We want to sort a list by its second element in descending order. | |
# The example illustrates the difference in the results of different | |
# process of sorting in descending order. | |
# Sort in ascending order, then use list reverse | |
>>> a = [('A', 1), ('C', 5), ('A', 2), ('B', 3), ('B', 5)] | |
>>> a.sort(key=lambda x: x[1]) | |
>>> print(a) | |
[('A', 1), ('A', 2), ('B', 3), ('C', 5), ('B', 5)] | |
>>> a.reverse() |
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 scope_test(): | |
def do_local(): | |
spam = "local spam" | |
def do_nonlocal(): | |
nonlocal spam | |
spam = "nonlocal spam" | |
def do_global(): | |
global spam | |
spam = "global spam" | |
spam = "test spam" |
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
#!/bin/bash | |
# Assumes a directory structure of: | |
# dir | |
# |-- skeleton | |
# | |-- testFile.java | |
# | +-- grade.sh (this file) | |
# | | |
# +-- testdata | |
# |-- input |
OlderNewer