Blog Archives

lesson13_ear_16_17_3

d=dict() for x in range(1,16): d[x]=x**2 print(d) d = {‘Red’: 1, ‘Green’: 2, ‘Blue’: 3} for color_key, value in d.items(): print(color_key, ‘corresponds to ‘, d[color_key]) keys = [‘red’, ‘green’, ‘blue’] values = [‘#FF0000′,’#008000’, ‘#0000FF’] color_dictionary = dict(zip(keys, values)) print(color_dictionary) color_dict

Posted in Uncategorized

lesson13_ear_16_17_2

def recursive_list_sum(data_list): total = 0 for element in data_list: if type(element) == list: total = total + recursive_list_sum(element) else: total = total + element return total print( recursive_list_sum([1, 2, [3,4],[5,6]]))  

Posted in Uncategorized

lesson13_ear_16_17_1

x = 11 counter = 0 while x != 1: print x x = x / 2 counter = counter + 2 if counter > 6: break print counter print ‘new’ x = 12.5 counter = 0 while x !=

Posted in Uncategorized

lesson12_ear_16_17_2

class Stack: def __init__(self): self.items = [] def isEmpty(self): return self.items == [] def push(self, item): self.items.append(item) def pop(self): return self.items.pop() def peek(self): return self.items[len(self.items)-1] def size(self): return len(self.items) s=Stack() print(s.isEmpty()) s.push(4) s.push(‘dog’) print(s.peek()) s.push(True) print(s.size()) print(s.isEmpty()) s.push(8.4) print(s.pop()) print(s.pop())

Posted in Uncategorized

lesson12_ear_16_17_1

class Queue: def __init__(self): self.items = [] def isEmpty(self): return self.items == [] def enqueue(self, item): self.items.insert(0,item) def dequeue(self): return self.items.pop() def size(self): return len(self.items) q = Queue() print q.size() print q.isEmpty() q.enqueue(8.4) q.enqueue(18) print q.dequeue() print q.size()  

Posted in Uncategorized

lesson_10_ear_16_17

# -*- coding: utf-8 -*- “”” Use of nested lists @authors: katkaranikola stkarlos “”” def nested_list(m,n): l = [] for i in range(0,m): k = [] for j in range(0,n): x = raw_input(“give 1 number: “) k.append(float(x)) l.append(k) print l

Posted in Uncategorized

lesson11_ear_16_17

# -*- coding: utf-8 -*- “”” Created on Mon May 29 09:36:54 2017 @author: 07sta “”” from numpy import * a = array([[3,8,1],[8,4,1],[2,1,4]]) print linalg.inv(a) print linalg.eig(a) import numpy as np import matplotlib.pyplot as plt x = np.linspace(0,2*np.pi,100) y =

Posted in Uncategorized

homework_on_defs_unsolved

# -*- coding: utf-8 -*- “”” fill up with the appropriate code the non completed lines @authors: katkaranikola stkarlos “”” # write a def that returns a list with the indices of the inserted list # that contains items which

Posted in Uncategorized

lesson9_17_ear_3

# -*- coding: utf-8 -*- “”” Examples of initializing a list with random numbers and processing it @authors: katkaranikola stkarlos “”” import random def create_list(num): l = [] for i in range(0,num): x = random.randint(1,15) l.append(x) print “your list is:

Posted in Uncategorized

lesson9_17_ear_2

# -*- coding: utf-8 -*- “”” Created on Thu May 18 14:21:59 2017 Simple Examples of defs with lists @authors: katkaranikola stkarlos “”” def max_listas(l): M = l[0] for i in range(1, len(l)): if l[i] > M: M = l[i]

Posted in Uncategorized