a = 1 print a print a.real print a.imag print a.bit_length a.bit_length? a.bit_length() b = [1,2,3,4] print len(b) print(b[0]) b[0] = 2 print b print b * 2 print b+1 print b + b new_b = b.append(5) print new_b print b c = (1,2,3,4) print c[0] c[0] = 2 print c + c d = {'key_the_first':1000.0, 'key_the_second':'woot!', 10:1 , (10,11):12} print d['key_the_first'] print d[10] print d[(10,11)] for x in b: print x for x in b: print x for lookfor in range(10): if lookfor in b: print 'I think we have a %s in b'%lookfor import os curdir = os.path.curdir listdir = os.listdir(curdir) print os.path.join(curdir, listdir[1]) def add_two_numbers(num1, num2): """ This is the function docstring. Ideally it is informative. For example: Add two numbers to each other. Parameters ---------- num1 : int/float A number num2 : int/float Another number Returns ------- sum_it : the sum of the inputs """ sum_it = num1 + num2 return sum_it add_two_numbers(1,2) add_two_numbers? import numpy as np # The array library - we'll come back to this one def word_count(url): """ Count word frequencies in the text body of a given url Parameters ---------- url : string The address of a url to be scraped Returns ------- word_dict : dict Frequency counts of the words """ import urllib url_get = urllib.urlretrieve(url) f = file(url_get[0]) txt = f.read() start_idx = txt.find('') end_idx = txt.find('') new_txt = txt[start_idx:end_idx] new_txt = new_txt.split(' ') word_dict = {} for word in new_txt: # Get rid of all kinds of html crud and the empty character: if not('>' in word or '<' in word or '=' in word or '-' in word or '&' in word or word == ''): if word in word_dict.keys(): word_dict[word] += 1 else: word_dict[word] = 1 vals = np.array(word_dict.values()) keys = np.array(word_dict.keys()) sort_idx = np.argsort(vals) return (vals[sort_idx][::-1], keys[sort_idx[::-1]]) word_arr = word_count('http://www.journalofvision.org/content/11/5/12.full?') to_plot_vals = word_arr[0][:50] to_plot_words = word_arr[1][:50] print to_plot_vals print to_plot_words %pylab inline fig, ax = plt.subplots(1) for word_idx in range(len(to_plot_words[11:])): ax.text(np.random.rand(), np.random.rand(), to_plot_words[11:][word_idx], fontsize=to_plot_vals[11:][word_idx]) ax.set_axis_off()