# Return Value vs. Side Effect my_list = [1, 2, 3, 4] my_list = my_list.append(5) print my_list other_list = [1, 2, 3, 4] other_list + [5] print other_list # Modification while iterating ##l1 = [1, 2, 0, 4, 0, 6] ##for num in l1: ## if num == 0: ## l1.remove(num) ##print l1 # Averaging ##def average(num_list): ## count = 0 ## total = 0 ## for num in num_list: ## count += 1 ## total += num ## return total/count # Indentations and colons ##l2 = [1, 2, 3, 4, 5] ##for num in l2 ##print num # Comparison vs. Assignment ##x == 1 ##print x ## ##x = 1 ##x == 2 ##print x ## ##x = 1 ##if x = 2: ## print "x is 2" ##else: ## print "x is not 2" # Non-updating conditions ##count = 10 ##while count > 0: ## print count # range index error ##def monotonically_increasing(num_list): ## for i in range(len(num_list)): ## if num_list[i+1] < num_list[i]: ## return False ## return True # Print vs. Return ##''' ##Inputs: two vectors, represented as lists with the same length ##Returns: The dot product of those two vectors ##Effects: None ##''' ##def dot_product(vec1, vec2): ## dot_prod = 0 ## for i in range(len(vec1)): ## dot_prod += vec1[i]*vec2[i] ## print dot_prod