├── 10Sep2017
├── filereadwrite
│ ├── .idea
│ │ ├── filereadwrite.iml
│ │ ├── misc.xml
│ │ ├── modules.xml
│ │ └── workspace.xml
│ ├── demo.txt
│ ├── demo1.txt
│ ├── file1.py
│ ├── file2.py
│ ├── file3.py
│ ├── file4.py
│ ├── file5.py
│ ├── file6.py
│ ├── file7.py
│ └── file8.py
└── objectoriented
│ ├── .idea
│ ├── misc.xml
│ ├── modules.xml
│ ├── objectoriented.iml
│ └── workspace.xml
│ ├── car.py
│ ├── electricalcar.py
│ ├── object1.py
│ ├── object2.py
│ ├── object3.py
│ ├── object4.py
│ ├── object5.py
│ ├── object6.py
│ ├── object7.py
│ └── object8.py
├── 13Aug2017
├── DemoInput
│ ├── .idea
│ │ ├── DemoInput.iml
│ │ ├── inspectionProfiles
│ │ │ └── profiles_settings.xml
│ │ ├── misc.xml
│ │ ├── modules.xml
│ │ └── workspace.xml
│ ├── Input1.py
│ ├── Input2.py
│ ├── Input3.py
│ ├── Input4.py
│ ├── While1.py
│ ├── While2.py
│ ├── While3.py
│ └── While4.py
├── Practice
│ ├── .idea
│ │ ├── Practice.iml
│ │ ├── inspectionProfiles
│ │ │ └── profiles_settings.xml
│ │ ├── misc.xml
│ │ ├── modules.xml
│ │ └── workspace.xml
│ ├── DuplicateRandomNumbers.py
│ ├── GuessNumber.py
│ └── PrimeNumber.py
└── RandomNumbers
│ ├── .idea
│ ├── RandomNumbers.iml
│ ├── inspectionProfiles
│ │ └── profiles_settings.xml
│ ├── misc.xml
│ ├── modules.xml
│ └── workspace.xml
│ ├── Demo.py
│ ├── random1.py
│ └── random2.py
├── 15Oct2017
├── datascience_chap2
│ ├── .idea
│ │ ├── datascience_chap2.iml
│ │ ├── misc.xml
│ │ ├── modules.xml
│ │ └── workspace.xml
│ ├── demo1.py
│ ├── demo10.py
│ ├── demo11.py
│ ├── demo12.py
│ ├── demo13.py
│ ├── demo14.py
│ ├── demo15.py
│ ├── demo16.py
│ ├── demo17.py
│ ├── demo18.py
│ ├── demo19.py
│ ├── demo2.py
│ ├── demo20.py
│ ├── demo21.py
│ ├── demo22.py
│ ├── demo23.py
│ ├── demo24.py
│ ├── demo25.py
│ ├── demo26.py
│ ├── demo27.py
│ ├── demo3.py
│ ├── demo4.py
│ ├── demo5.py
│ ├── demo6.py
│ ├── demo7.py
│ ├── demo8.py
│ └── demo9.py
└── untitled
│ ├── .idea
│ ├── misc.xml
│ ├── modules.xml
│ ├── untitled.iml
│ └── workspace.xml
│ └── demo1.py
├── 17Sep2017
├── exceptions
│ ├── .idea
│ │ ├── exceptions.iml
│ │ ├── misc.xml
│ │ ├── modules.xml
│ │ └── workspace.xml
│ ├── exception12.py
│ ├── exceptions1.py
│ ├── exceptions10.py
│ ├── exceptions11.py
│ ├── exceptions12.py
│ ├── exceptions13.py
│ ├── exceptions14.py
│ ├── exceptions15.py
│ ├── exceptions16.py
│ ├── exceptions2.py
│ ├── exceptions3.py
│ ├── exceptions4.py
│ ├── exceptions5.py
│ ├── exceptions6.py
│ ├── exceptions7.py
│ ├── exceptions8.py
│ └── exceptions9.py
└── storingdata
│ ├── .idea
│ ├── misc.xml
│ ├── modules.xml
│ ├── storingdata.iml
│ └── workspace.xml
│ ├── numbers.json
│ ├── numbers2.json
│ ├── numbers3.json
│ ├── numbers4.json
│ ├── q10.py
│ ├── sotring2.py
│ ├── storing1.py
│ ├── storing3.py
│ ├── storing4.py
│ ├── storing5.py
│ ├── storing6.py
│ ├── storing7.py
│ └── storing8.py
├── 20Aug2017
├── DemoDictionaries
│ ├── .idea
│ │ ├── DemoDictionaries.iml
│ │ ├── inspectionProfiles
│ │ │ └── profiles_settings.xml
│ │ ├── misc.xml
│ │ ├── modules.xml
│ │ └── workspace.xml
│ ├── Dictioanry13.py
│ ├── Dictionary1.py
│ ├── Dictionary10.py
│ ├── Dictionary11.py
│ ├── Dictionary12.py
│ ├── Dictionary13.py
│ ├── Dictionary14.py
│ ├── Dictionary2.py
│ ├── Dictionary5.py
│ ├── Dictionary6.py
│ ├── Dictionary7.py
│ ├── Dictionary8.py
│ ├── Dictionary9.py
│ ├── Distionary3.py
│ └── Distionary4.py
└── Functions
│ ├── .idea
│ ├── Functions.iml
│ ├── inspectionProfiles
│ │ └── profiles_settings.xml
│ ├── misc.xml
│ ├── modules.xml
│ └── workspace.xml
│ ├── Func1.py
│ ├── Func10.py
│ ├── Func11.py
│ ├── Func12.py
│ ├── Func13.py
│ ├── Func2.py
│ ├── Func3.py
│ ├── Func4.py
│ ├── Func5.py
│ ├── Func6.py
│ ├── Func7.py
│ ├── Func8.py
│ └── Func9.py
├── 22Oct2017
└── datascience_chap1
│ ├── .idea
│ ├── datascience_chap1.iml
│ ├── misc.xml
│ ├── modules.xml
│ └── workspace.xml
│ ├── demo1.py
│ ├── demo2.py
│ ├── demo3.py
│ ├── demo4.py
│ ├── demo5.py
│ ├── demo6.py
│ └── demo7.py
├── 23July2017
└── hello
│ ├── .idea
│ ├── hello.iml
│ ├── inspectionProfiles
│ │ └── profiles_settings.xml
│ ├── misc.xml
│ ├── modules.xml
│ └── workspace.xml
│ ├── eight.py
│ ├── fifth.py
│ ├── first.py
│ ├── forth.py
│ ├── second.py
│ ├── seventh.py
│ ├── sixth.py
│ └── third.py
├── 24Sep2017
└── datascience_chap2
│ ├── .idea
│ ├── datascience_chap2.iml
│ ├── misc.xml
│ ├── modules.xml
│ └── workspace.xml
│ ├── abc.ipynb
│ ├── demo1.py
│ ├── demo10.py
│ ├── demo2.py
│ ├── demo3.py
│ ├── demo4.py
│ ├── demo5.py
│ ├── demo6.py
│ ├── demo7.py
│ ├── demo8.py
│ └── demo9.py
├── 27Aug2017
└── Objects
│ ├── .idea
│ ├── Objects.iml
│ ├── misc.xml
│ ├── modules.xml
│ └── workspace.xml
│ ├── object3.py
│ ├── objects1.py
│ ├── objects10.py
│ ├── objects11.py
│ ├── objects12.py
│ ├── objects13.py
│ ├── objects14.py
│ ├── objects2.py
│ ├── objects4.py
│ ├── objects5.py
│ ├── objects6.py
│ ├── objects7.py
│ ├── objects8.py
│ └── objects9.py
├── 29Oct2017
└── 29Oct2017
│ ├── datascience_chap1
│ ├── .idea
│ │ ├── datascience_chap1.iml
│ │ ├── misc.xml
│ │ ├── modules.xml
│ │ └── workspace.xml
│ ├── demo1.py
│ ├── demo2.py
│ ├── demo3.py
│ ├── demo4.py
│ ├── demo5.py
│ ├── demo6.py
│ ├── demo7.py
│ └── demo8.py
│ └── demoObjects
│ ├── .idea
│ ├── demoObjects.iml
│ ├── misc.xml
│ ├── modules.xml
│ └── workspace.xml
│ └── obj1.py
├── 30July2017
├── DemoList
│ ├── .idea
│ │ ├── DemoList.iml
│ │ ├── inspectionProfiles
│ │ │ └── profiles_settings.xml
│ │ ├── misc.xml
│ │ ├── modules.xml
│ │ └── workspace.xml
│ ├── List1.py
│ ├── List10.py
│ ├── List2.py
│ ├── List3.py
│ ├── List4.py
│ ├── List5.py
│ ├── List6.py
│ ├── List7.py
│ ├── List8.py
│ └── List9.py
└── DemoListChap4
│ ├── .idea
│ ├── DemoListChap4.iml
│ ├── inspectionProfiles
│ │ └── profiles_settings.xml
│ ├── misc.xml
│ ├── modules.xml
│ └── workspace.xml
│ ├── List1.py
│ ├── List2.py
│ ├── List3.py
│ ├── List4.py
│ ├── List5.py
│ ├── List6.py
│ └── List7.py
├── 6Aug2017
├── DemoIfElse
│ ├── .idea
│ │ ├── DemoIfElse.iml
│ │ ├── inspectionProfiles
│ │ │ └── profiles_settings.xml
│ │ ├── misc.xml
│ │ ├── modules.xml
│ │ └── workspace.xml
│ ├── IfElse1.py
│ ├── IfElse2.py
│ ├── IfElse3.py
│ ├── IfElse4.py
│ ├── IfElse5.py
│ └── InOperator.py
├── DemoList
│ ├── .idea
│ │ ├── DemoList.iml
│ │ ├── inspectionProfiles
│ │ │ └── profiles_settings.xml
│ │ ├── misc.xml
│ │ ├── modules.xml
│ │ └── workspace.xml
│ ├── List1.py
│ ├── List10.py
│ ├── List11.py
│ ├── List12.py
│ ├── List13.py
│ ├── List14.py
│ ├── List15.py
│ ├── List16.py
│ ├── List17.py
│ ├── List18.py
│ ├── List2.py
│ ├── List3.py
│ ├── List4.py
│ ├── List5.py
│ ├── List6.py
│ ├── List7.py
│ ├── List8.py
│ └── List9.py
└── DemoTuple
│ ├── .idea
│ ├── DemoTuple.iml
│ ├── inspectionProfiles
│ │ └── profiles_settings.xml
│ ├── misc.xml
│ ├── modules.xml
│ └── workspace.xml
│ ├── tuple1.py
│ ├── tuple2.py
│ ├── tuple3.py
│ ├── tuple4.py
│ ├── tuple5.py
│ └── tuple6.py
├── 8Oct2017
└── datascience_chap2
│ ├── .idea
│ ├── datascience_chap2.iml
│ ├── misc.xml
│ ├── modules.xml
│ └── workspace.xml
│ ├── demo1.py
│ ├── demo10.py
│ ├── demo11.py
│ ├── demo12.py
│ ├── demo13.py
│ ├── demo14.py
│ ├── demo15.py
│ ├── demo16.py
│ ├── demo17.py
│ ├── demo2.py
│ ├── demo3.py
│ ├── demo4.py
│ ├── demo5.py
│ ├── demo6.py
│ ├── demo7.py
│ ├── demo8.py
│ └── demo9.py
└── README.md
/10Sep2017/filereadwrite/.idea/filereadwrite.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/10Sep2017/filereadwrite/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/10Sep2017/filereadwrite/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/10Sep2017/filereadwrite/demo.txt:
--------------------------------------------------------------------------------
1 | Hello World 1
2 | Hello World 2
3 | Hello World 3
4 | Hello World 4
5 | Hello World 5
--------------------------------------------------------------------------------
/10Sep2017/filereadwrite/demo1.txt:
--------------------------------------------------------------------------------
1 | I love programming!
2 |
--------------------------------------------------------------------------------
/10Sep2017/filereadwrite/file1.py:
--------------------------------------------------------------------------------
1 | with open('demo.txt') as fileObj:
2 | content = fileObj.read()
3 | print(content)
--------------------------------------------------------------------------------
/10Sep2017/filereadwrite/file2.py:
--------------------------------------------------------------------------------
1 | with open('demo.txt') as fileObj:
2 | for line in fileObj:
3 | print(line)
--------------------------------------------------------------------------------
/10Sep2017/filereadwrite/file3.py:
--------------------------------------------------------------------------------
1 | with open('demo.txt') as fileObj:
2 | lines = fileObj.readlines()
3 | print(lines)
--------------------------------------------------------------------------------
/10Sep2017/filereadwrite/file4.py:
--------------------------------------------------------------------------------
1 | mylist = ["hello","test"]
2 | with open('demo.txt') as fileObj:
3 | lines = fileObj.readlines()
4 | mylist = mylist + lines
5 | print(mylist)
--------------------------------------------------------------------------------
/10Sep2017/filereadwrite/file5.py:
--------------------------------------------------------------------------------
1 |
2 | with open('demo1.txt','w') as fileObj:
3 | fileObj.write("I love programming!")
--------------------------------------------------------------------------------
/10Sep2017/filereadwrite/file6.py:
--------------------------------------------------------------------------------
1 |
2 | with open('demo1.txt','a') as fileObj:
3 | fileObj.write("I love programming!\n")
4 | #content = fileObj.read()
5 | #print(content)
--------------------------------------------------------------------------------
/10Sep2017/filereadwrite/file7.py:
--------------------------------------------------------------------------------
1 |
2 | with open('demo1.txt','r+') as fileObj:
3 | fileObj.write("I love programming!\n")
4 |
5 | fileObj.seek(0)
6 | content = fileObj.readlines()
7 | print(content)
8 |
9 |
--------------------------------------------------------------------------------
/10Sep2017/filereadwrite/file8.py:
--------------------------------------------------------------------------------
1 | import os;
2 |
3 | p = os.path.isfile("demo.txt")
4 | p1 = os.path.isdir("C:\\Windows")
5 | dirList = os.listdir("C:\\Windows")
6 | print(p)
7 | print(p1)
8 | print(dirList)
--------------------------------------------------------------------------------
/10Sep2017/objectoriented/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/10Sep2017/objectoriented/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/10Sep2017/objectoriented/.idea/objectoriented.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/10Sep2017/objectoriented/car.py:
--------------------------------------------------------------------------------
1 | class Car():
2 |
3 | def __init__(self,make,model,year):
4 | self.make = make
5 | self.model = model
6 | self.year = year
7 | self.__odometer_reading = 5
8 |
9 |
10 | def get_descriptive_name(self):
11 | print("In Car")
12 | long_name = str(self.year)+ ' '+self.make + ' ' + self.model + ' '+ str(self.__odometer_reading)
13 | return long_name
14 |
15 | def update_odometer(self, val):
16 | self.__odometer_reading = val
17 |
18 | def get_odometer(self):
19 | return self.__odometer_reading
20 |
21 |
--------------------------------------------------------------------------------
/10Sep2017/objectoriented/electricalcar.py:
--------------------------------------------------------------------------------
1 | from car import Car
2 | class ElectricCar(Car):
3 | '''ElectricCar'''
4 | def __init__(self,make,model,year):
5 | super().__init__(make,model,year)
6 | self.name = "Test 1 car"
7 |
8 | def charge(self):
9 | print("Electric Car is charging")
10 |
11 | def get_descriptive_name(self):
12 | print("In ElectricCar")
13 | long_name = str(self.year)+ ' '+self.make + ' ' + self.model
14 | return long_name
15 |
16 |
--------------------------------------------------------------------------------
/10Sep2017/objectoriented/object1.py:
--------------------------------------------------------------------------------
1 | class Car():
2 |
3 | def __init__(self,make,model,year):
4 | self.make = make
5 | self.model = model
6 | self.year = year
7 | self.__odometer_reading = 5
8 |
9 |
10 | def get_descriptive_name(self):
11 | long_name = str(self.year)+ ' '+self.make + ' ' + self.model + ' '+ str(self.__odometer_reading)
12 | return long_name
13 |
14 | def update_odometer(self, val):
15 | self.__odometer_reading = val
16 |
17 | def get_odometer(self):
18 | return self.__odometer_reading
19 |
20 | def __start(self):
21 | print("Car started")
22 |
23 | class ElectricCar(Car):
24 | '''ElectricCar'''
25 | def __init__(self,make,model,year):
26 | super().__init__(make,model,year)
27 | #self.make = make
28 | #self.model = model
29 | #self.year = year
30 |
31 |
32 |
33 | c = Car('audi', 'a4', 2016)
34 | ec = ElectricCar('Tesla', 's4', 2016)
35 | print(ec.get_descriptive_name())
36 | #ec.__start()
37 |
38 |
39 |
--------------------------------------------------------------------------------
/10Sep2017/objectoriented/object2.py:
--------------------------------------------------------------------------------
1 | class Car():
2 |
3 | def __init__(self,make,model,year):
4 | self.make = make
5 | self.model = model
6 | self.year = year
7 | self.__odometer_reading = 5
8 |
9 |
10 | def get_descriptive_name(self):
11 | long_name = str(self.year)+ ' '+self.make + ' ' + self.model + ' '+ str(self.__odometer_reading)
12 | return long_name
13 |
14 | def update_odometer(self, val):
15 | self.__odometer_reading = val
16 |
17 | def get_odometer(self):
18 | return self.__odometer_reading
19 |
20 |
21 | class ElectricCar(Car):
22 | '''ElectricCar'''
23 | def __init__(self,make,model,year):
24 | super().__init__(make,model,year)
25 | self.name = "Test 1 car"
26 |
27 | def charge(self):
28 | print("Electric Car is charging")
29 |
30 |
31 | c = Car('audi', 'a4', 2016)
32 | ec = ElectricCar('Tesla', 's4', 2016)
33 | print(ec.get_descriptive_name())
34 | ec.charge()
35 | #c.charge()
36 | print(ec.name)
37 |
38 | #ec = c;
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/10Sep2017/objectoriented/object3.py:
--------------------------------------------------------------------------------
1 | class Car():
2 |
3 | def __init__(self,make,model,year):
4 | self.make = make
5 | self.model = model
6 | self.year = year
7 | self.__odometer_reading = 5
8 |
9 |
10 | def get_descriptive_name(self):
11 | print("In Car")
12 | long_name = str(self.year)+ ' '+self.make + ' ' + self.model + ' '+ str(self.__odometer_reading)
13 | return long_name
14 |
15 | def update_odometer(self, val):
16 | self.__odometer_reading = val
17 |
18 | def get_odometer(self):
19 | return self.__odometer_reading
20 |
21 |
22 | class ElectricCar(Car):
23 | '''ElectricCar'''
24 | def __init__(self,make,model,year):
25 | super().__init__(make,model,year)
26 | self.name = "Test 1 car"
27 |
28 | def charge(self):
29 | print("Electric Car is charging")
30 |
31 | def get_descriptive_name(self):
32 | print("In ElectricCar")
33 | long_name = str(self.year)+ ' '+self.make + ' ' + self.model
34 | return long_name
35 |
36 |
37 | c = Car('audi', 'a4', 2016)
38 | ec = ElectricCar('Tesla', 's4', 2016)
39 | print(ec.get_descriptive_name())
40 | ec.charge()
41 | #c.charge()
42 | print(ec.name)
43 |
44 | #ec = c;
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/10Sep2017/objectoriented/object4.py:
--------------------------------------------------------------------------------
1 | class Car():
2 |
3 | def __init__(self,make,model,year):
4 | self.make = make
5 | self.model = model
6 | self.year = year
7 | self.__odometer_reading = 5
8 |
9 | def doSomething(self):
10 | print("in car do something")
11 | return self.get_descriptive_name()
12 |
13 | def get_descriptive_name(self):
14 | print("In Car")
15 | long_name = str(self.year)+ ' '+self.make + ' ' + self.model + ' '+ str(self.__odometer_reading)
16 | return long_name
17 |
18 | class ElectricCar(Car):
19 | '''ElectricCar'''
20 | def __init__(self,make,model,year):
21 | super().__init__(make,model,year)
22 | self.name = "Test 1 car"
23 |
24 | def charge(self):
25 | print("Electric Car is charging")
26 |
27 | def get_descriptive_name(self):
28 | print("In ElectricCar")
29 | long_name = str(self.year)+ ' '+self.make + ' ' + self.model
30 | return long_name
31 |
32 |
33 | c = Car('audi', 'a4', 2016)
34 | ec = ElectricCar('Tesla', 's4', 2016)
35 | print(ec.doSomething())
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/10Sep2017/objectoriented/object5.py:
--------------------------------------------------------------------------------
1 | class Car():
2 |
3 | def __init__(self,make,model,year,battery):
4 | self.make = make
5 | self.model = model
6 | self.year = year
7 | self.battery = battery
8 | self.__odometer_reading = 5
9 |
10 |
11 |
12 | def get_descriptive_name(self):
13 | print("In Car")
14 | long_name = str(self.year)+ ' '+self.make + ' ' + self.model + ' '+ str(self.__odometer_reading)
15 | return long_name
16 |
17 |
18 | class Battery():
19 | """A simple attempt to model a battery for an electric car."""
20 | def __init__(self, battery_size=70):
21 | """Initialize the battery's attributes."""
22 | self.battery_size = battery_size
23 |
24 | def describe_battery(self):
25 | """Print a statement describing the battery size."""
26 | print("This car has a " + str(self.battery_size) + "-kWh battery.")
27 |
28 | b = Battery()
29 | c = Car('audi', 'a4', 2016, b)
30 | c.battery.describe_battery()
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/10Sep2017/objectoriented/object6.py:
--------------------------------------------------------------------------------
1 | from car import Car
2 | from electricalcar import ElectricCar
3 |
4 | c = Car('audi', 'a4', 2016, b)
--------------------------------------------------------------------------------
/10Sep2017/objectoriented/object7.py:
--------------------------------------------------------------------------------
1 | from car import Car as c
2 |
3 | import electricalcar as ect
4 |
5 | abc = c('audi', 'a4', 2016)
6 | e = ect.ElectricCar()
7 |
--------------------------------------------------------------------------------
/10Sep2017/objectoriented/object8.py:
--------------------------------------------------------------------------------
1 | class Car():
2 | def dosomething(self):
3 | print("car dosomething")
4 |
5 | class AutomaticCar():
6 | def dosomething(self):
7 | print("AutomaticCar dosomething")
8 | def testAuto(self):
9 | print("AutomaticCar auto")
10 |
11 | class ElectricalCar(AutomaticCar,Car):
12 | def workig(self):
13 | print("working")
14 |
15 |
16 | a = Car()
17 | b = AutomaticCar()
18 | c = ElectricalCar()
19 | c.dosomething()
20 | c.testAuto()
21 |
--------------------------------------------------------------------------------
/13Aug2017/DemoInput/.idea/DemoInput.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/13Aug2017/DemoInput/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/13Aug2017/DemoInput/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/13Aug2017/DemoInput/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/13Aug2017/DemoInput/Input1.py:
--------------------------------------------------------------------------------
1 | message = input("Enter your name ")
2 | print("Hello "+message+"!")
--------------------------------------------------------------------------------
/13Aug2017/DemoInput/Input2.py:
--------------------------------------------------------------------------------
1 | age = input("How old are you? ")
2 | age = int(age)
3 | print(age)
4 | if age>18:
5 | print("Here is yor CNIC")
6 | else :
7 | print("Grow up")
--------------------------------------------------------------------------------
/13Aug2017/DemoInput/Input3.py:
--------------------------------------------------------------------------------
1 | age = int(input("How old are you? "))
2 | print(age)
3 | if age>18:
4 | print("Here is yor CNIC")
5 | else :
6 | print("Grow up")
--------------------------------------------------------------------------------
/13Aug2017/DemoInput/Input4.py:
--------------------------------------------------------------------------------
1 | num = int(input("Enter your number"))
2 | if num % 2 == 0:
3 | print("The number "+str(num)+" even")
4 | else:
5 | print("The number " + str(num) + " odd")
--------------------------------------------------------------------------------
/13Aug2017/DemoInput/While1.py:
--------------------------------------------------------------------------------
1 | current_number = 1
2 |
3 | while current_number <= 5:
4 | #print(current_number)
5 | current_number += 1
6 |
7 | print(current_number)
8 |
--------------------------------------------------------------------------------
/13Aug2017/DemoInput/While2.py:
--------------------------------------------------------------------------------
1 | current_number = int(input("Enter number "))
2 | num = 0
3 |
4 | while num < current_number:
5 | print(num)
6 | num += 1
7 |
8 | print("Final",num)
9 |
--------------------------------------------------------------------------------
/13Aug2017/DemoInput/While3.py:
--------------------------------------------------------------------------------
1 | current_number = int(input("Enter number "))
2 | num = 0
3 |
4 | while num < current_number:
5 | num += 1
6 | if num == 3:
7 | break
8 | print(num)
9 |
10 |
11 | print("Final",num)
12 |
--------------------------------------------------------------------------------
/13Aug2017/DemoInput/While4.py:
--------------------------------------------------------------------------------
1 | current_number = int(input("Enter number "))
2 | num = 0
3 |
4 | while num < current_number:
5 | num += 1
6 | if num == 3:
7 | continue
8 | print(num)
9 |
10 |
11 | print("Final",num)
12 |
--------------------------------------------------------------------------------
/13Aug2017/Practice/.idea/Practice.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/13Aug2017/Practice/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/13Aug2017/Practice/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/13Aug2017/Practice/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/13Aug2017/Practice/DuplicateRandomNumbers.py:
--------------------------------------------------------------------------------
1 | from random import randint
2 | max = int(input("Enter max number"))
3 | count = max+1
4 | mylist = []
5 |
6 | while len(mylist) != count:
7 | num = randint(0, max)
8 | if( num not in mylist):
9 | mylist.append(num)
10 |
11 | print (mylist)
--------------------------------------------------------------------------------
/13Aug2017/Practice/GuessNumber.py:
--------------------------------------------------------------------------------
1 | # 1) generate random number
2 | # 2) user guess number with input
3 | # 3) if number match you win
4 | # else you lose
5 | # 4) if user input is incorrect
6 | # give him 3 chance
7 |
8 | # 5) after win or lose ask user
9 | # do you want to continue
10 | # if user say yes Generate
11 | # New Random number
12 | # start from Point 1 again
--------------------------------------------------------------------------------
/13Aug2017/Practice/PrimeNumber.py:
--------------------------------------------------------------------------------
1 | value = int(input("Enter value? "))
2 | check = True
3 | num = 2
4 | while num<=value/2:
5 | if(value % num ==0):
6 | check = False
7 | break
8 | num +=1
9 | if check:
10 | print("This is Prime Number.")
11 | else:
12 |
13 | print("This isn't Prime Number.")
--------------------------------------------------------------------------------
/13Aug2017/RandomNumbers/.idea/RandomNumbers.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/13Aug2017/RandomNumbers/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/13Aug2017/RandomNumbers/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/13Aug2017/RandomNumbers/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/13Aug2017/RandomNumbers/Demo.py:
--------------------------------------------------------------------------------
1 | play = "yes"
2 |
3 | print(play is "yes")
--------------------------------------------------------------------------------
/13Aug2017/RandomNumbers/random1.py:
--------------------------------------------------------------------------------
1 | from random import randint
2 |
3 |
4 | num = randint(1,15)
5 | print(num)
--------------------------------------------------------------------------------
/13Aug2017/RandomNumbers/random2.py:
--------------------------------------------------------------------------------
1 | from random import randint
2 | num = 0
3 | mylist = []
4 | for val in range(0,10):
5 | num = randint(1,15)
6 | mylist.append(num)
7 | print(num)
8 |
9 | print(mylist)
10 |
11 | val = 6;
12 | val in mylist
--------------------------------------------------------------------------------
/15Oct2017/datascience_chap2/.idea/datascience_chap2.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/15Oct2017/datascience_chap2/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/15Oct2017/datascience_chap2/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/15Oct2017/datascience_chap2/demo1.py:
--------------------------------------------------------------------------------
1 | def exp(base, power):
2 | return base ** power
3 |
4 | def two_to_the(power):
5 | return exp(2, power)
6 |
7 | print(exp(2,4))
8 | print(exp(2,5))
9 | print(exp(2,6))
10 |
11 | print(two_to_the(8))
--------------------------------------------------------------------------------
/15Oct2017/datascience_chap2/demo10.py:
--------------------------------------------------------------------------------
1 | from functools import partial
2 | def double(x):
3 | return 2 * x
4 |
5 | xs = [1, 2, 3, 4]
6 | list_doubler = partial(map, double)
7 |
8 | print(list(list_doubler(xs)))
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/15Oct2017/datascience_chap2/demo11.py:
--------------------------------------------------------------------------------
1 | from functools import partial
2 |
3 | def is_even(x):
4 | """True if x is even, False if x is odd"""
5 | return x % 2 == 0
6 | #return True
7 |
8 | xs = [1, 2, 3, 4]
9 |
10 | x_evens = filter(is_even, xs) # same as above
11 | print(list(x_evens))
12 | #list_evener = partial(filter, is_even) # *function* that filters a list
13 | #x_evens = list_evener(xs)
--------------------------------------------------------------------------------
/15Oct2017/datascience_chap2/demo12.py:
--------------------------------------------------------------------------------
1 | def multiply(x, y):
2 | return x * y
3 |
4 | a = multiply(1,2)
5 | print(a)
6 | b = multiply(a,3)
7 | print(b)
8 | c = multiply(b,4)
9 | print(c)
--------------------------------------------------------------------------------
/15Oct2017/datascience_chap2/demo13.py:
--------------------------------------------------------------------------------
1 | from functools import reduce
2 | def multiply(x, y):
3 | return x * y
4 | xs = [1, 2, 3, 4]
5 | x_product = reduce(multiply, xs)
6 |
7 | print(x_product)
--------------------------------------------------------------------------------
/15Oct2017/datascience_chap2/demo14.py:
--------------------------------------------------------------------------------
1 | documents = ["hello","world","new","that","working"]
2 |
3 | for i, document in enumerate(documents):
4 | print("I = "+str(i)+" doc = "+document)
--------------------------------------------------------------------------------
/15Oct2017/datascience_chap2/demo15.py:
--------------------------------------------------------------------------------
1 | list1 = ['a', 'b','d', 'c',]
2 | list2 = [1, 2, 3,4,5,6]
3 | print(list(zip(list1, list2)))
--------------------------------------------------------------------------------
/15Oct2017/datascience_chap2/demo16.py:
--------------------------------------------------------------------------------
1 | docs = [(1,"a"),(2,"b","rer"),(3,"c"),(4,"d")]
2 |
3 | a,b = zip(*docs)
4 |
5 | print(a)
6 | print(b)
--------------------------------------------------------------------------------
/15Oct2017/datascience_chap2/demo17.py:
--------------------------------------------------------------------------------
1 | def add(a, b):
2 | return a + b
3 |
4 | print(add(2,4))
5 | print(add(*[2,4]))
--------------------------------------------------------------------------------
/15Oct2017/datascience_chap2/demo18.py:
--------------------------------------------------------------------------------
1 | def myfunction(x):
2 | return x * 3
3 |
4 | def doubler(f):
5 | return 4 + f(6)
6 |
7 | print(doubler(myfunction))
8 |
--------------------------------------------------------------------------------
/15Oct2017/datascience_chap2/demo19.py:
--------------------------------------------------------------------------------
1 | def myfunction(x):
2 | return x * 3
3 | def doubler(f):
4 | def g(z):
5 | return z + f(6)
6 | return g
7 | myfunc = doubler(myfunction)
8 | print(myfunc)
9 | print(myfunc(2))
10 |
11 |
--------------------------------------------------------------------------------
/15Oct2017/datascience_chap2/demo2.py:
--------------------------------------------------------------------------------
1 | from functools import partial
2 |
3 | def exp(base, power):
4 | return base ** power
5 |
6 | two_to_the = partial(exp, 2)
7 |
8 | print(two_to_the(3))
9 | print(two_to_the(6))
10 | print(two_to_the(9))
11 |
--------------------------------------------------------------------------------
/15Oct2017/datascience_chap2/demo20.py:
--------------------------------------------------------------------------------
1 | def acceptArray(*a):
2 | print(a)
3 | print(a[0])
4 | print(a[4])
5 |
6 | acceptArray(3,5,7,8,9)
--------------------------------------------------------------------------------
/15Oct2017/datascience_chap2/demo21.py:
--------------------------------------------------------------------------------
1 | def acceptArray(*a,b):
2 | print(a)
3 | print(a[0])
4 | print(a[4])
5 |
6 | acceptArray(3,5,7,8,9,7,b=34)
--------------------------------------------------------------------------------
/15Oct2017/datascience_chap2/demo22.py:
--------------------------------------------------------------------------------
1 | def acceptArray(b,*a):
2 | print(a)
3 | print(a[0])
4 | print(a[4])
5 |
6 | acceptArray(3,5,7,8,9,7)
--------------------------------------------------------------------------------
/15Oct2017/datascience_chap2/demo23.py:
--------------------------------------------------------------------------------
1 | #Not allowed
2 | #def acceptArray(**b,a):
3 | def acceptArray(**b):
4 | print(b)
5 |
6 | acceptArray(hello="work",new="test")
--------------------------------------------------------------------------------
/15Oct2017/datascience_chap2/demo24.py:
--------------------------------------------------------------------------------
1 | def acceptArray(a,**b):
2 | print(a)
3 | print(b)
4 |
5 | acceptArray(34,hello="work",new="test")
6 | acceptArray(hello="work",new="test",a=23)
7 | #acceptArray(hello="work",new="test",23)
--------------------------------------------------------------------------------
/15Oct2017/datascience_chap2/demo25.py:
--------------------------------------------------------------------------------
1 | def other_way_magic(x, y, z):
2 | return x + y + z
3 |
4 | x_y_list = [1, 2]
5 | z_dict = { "z" : 3 }
6 | print(other_way_magic(*x_y_list, **z_dict)) # 6
--------------------------------------------------------------------------------
/15Oct2017/datascience_chap2/demo26.py:
--------------------------------------------------------------------------------
1 | def acceptArray(**b):
2 | print(b)
3 |
4 | acceptArray()
--------------------------------------------------------------------------------
/15Oct2017/datascience_chap2/demo27.py:
--------------------------------------------------------------------------------
1 | def f2(x, y):
2 | return x + y
3 |
4 | def f3(x, y,z):
5 | return x + y +z
6 |
7 | def doubler_correct(f):
8 | """works no matter what kind of inputs f expects"""
9 | def g(*args, **kwargs):
10 | """whatever arguments g is supplied, pass them through to f"""
11 | return 2 * f(*args, **kwargs)
12 | return g
13 |
14 | g = doubler_correct(f2)
15 | #print(g(1, 2,3)) # 6
16 | print(g(1, 2)) # 6
17 | print("=======")
18 |
19 | g1 = doubler_correct(f3)
20 | print(g1(1, 2,3)) # 6
--------------------------------------------------------------------------------
/15Oct2017/datascience_chap2/demo3.py:
--------------------------------------------------------------------------------
1 | from functools import partial
2 |
3 | def exp(base, power):
4 | return base ** power
5 |
6 | two_to_the = partial(exp, 2,3)
7 |
8 | print(two_to_the())
9 |
--------------------------------------------------------------------------------
/15Oct2017/datascience_chap2/demo4.py:
--------------------------------------------------------------------------------
1 | from functools import partial
2 |
3 | def exp(base, power):
4 | return base ** power
5 |
6 | two_to_the = partial(exp,power=3)
7 |
8 | print(two_to_the(5))
9 |
--------------------------------------------------------------------------------
/15Oct2017/datascience_chap2/demo5.py:
--------------------------------------------------------------------------------
1 | def double(x):
2 | return 2 * x
3 |
4 | #print(double(4))
5 | xs = [1, 2, 3, 4]
6 | xs2 = []
7 | for x3 in xs:
8 | print(x3*2)
9 | #xs2.append(double(x3))
10 |
11 |
12 |
--------------------------------------------------------------------------------
/15Oct2017/datascience_chap2/demo6.py:
--------------------------------------------------------------------------------
1 | def double(x):
2 | return 2 * x
3 |
4 | #print(double(4))
5 | xs = [1, 2, 3, 4]
6 | xs2 = []
7 | for x3 in xs:
8 | print(double(x3))
9 | #xs2.append(double(x3))
10 |
11 |
12 |
--------------------------------------------------------------------------------
/15Oct2017/datascience_chap2/demo7.py:
--------------------------------------------------------------------------------
1 | import functools
2 | def double(x):
3 | return 2 * x
4 |
5 | #print(double(4))
6 | xs = [1, 2, 3, 4]
7 | xs2 = []
8 | for x3 in xs:
9 | #print(double(x3))
10 | xs2.append(double(x3))
11 |
12 | print(xs2)
13 |
14 |
15 |
--------------------------------------------------------------------------------
/15Oct2017/datascience_chap2/demo8.py:
--------------------------------------------------------------------------------
1 | def double(x):
2 | return 2 * x
3 |
4 | #print(double(4))
5 | xs = [1, 2, 3, 4]
6 | xs2 = [double(x3) for x3 in xs]
7 |
8 | print(xs2)
9 |
10 |
11 |
--------------------------------------------------------------------------------
/15Oct2017/datascience_chap2/demo9.py:
--------------------------------------------------------------------------------
1 | def double(x):
2 | return 2 * x
3 |
4 |
5 | xs = [1, 2, 3, 4]
6 | xs2 = map(double,xs)
7 |
8 | #print(list(xs2))
9 |
10 | for a in xs2:
11 | print(a)
12 |
13 | print("test")
14 | for a in xs2:
15 | print(a)
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/15Oct2017/untitled/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/15Oct2017/untitled/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/15Oct2017/untitled/.idea/untitled.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/15Oct2017/untitled/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 | 1508060266863
94 |
95 |
96 | 1508060266863
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
--------------------------------------------------------------------------------
/15Oct2017/untitled/demo1.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeeshanhanif/python-code/6bee32795439f59e297e69db93dde7bbf2ecd6d2/15Oct2017/untitled/demo1.py
--------------------------------------------------------------------------------
/17Sep2017/exceptions/.idea/exceptions.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/17Sep2017/exceptions/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/17Sep2017/exceptions/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/17Sep2017/exceptions/exception12.py:
--------------------------------------------------------------------------------
1 | print("First")
2 | a = 5
3 | b = 0
4 | d = []
5 | try:
6 | c = a/b
7 | e = d[5]
8 | except ZeroDivisionError:
9 | print("Handel ZeroDivisionError")
10 | except:
11 | print("Handle Error")
12 | else:
13 | print(c)
14 | finally:
15 | print("Finally will always run")
16 |
17 | print("last")
18 |
19 |
--------------------------------------------------------------------------------
/17Sep2017/exceptions/exceptions1.py:
--------------------------------------------------------------------------------
1 | print("First")
2 | a = 5
3 | b = 0
4 | try:
5 | c = a/b
6 | print(c)
7 | except ZeroDivisionError:
8 | print("Handle ZeroDivisionError")
9 |
10 |
11 | print("last")
12 |
13 |
--------------------------------------------------------------------------------
/17Sep2017/exceptions/exceptions10.py:
--------------------------------------------------------------------------------
1 | print("First")
2 | a = 5
3 | b = 2
4 | d = []
5 | try:
6 | c = a/b
7 | e = d[5]
8 | except ZeroDivisionError:
9 | print("Handel ZeroDivisionError")
10 | except Exception as e:
11 | print("Handle Error == " +str(e))
12 | else:
13 | print(c)
14 |
15 | print("last")
16 |
17 |
--------------------------------------------------------------------------------
/17Sep2017/exceptions/exceptions11.py:
--------------------------------------------------------------------------------
1 | print("First")
2 | a = 5
3 | b = 2
4 | d = []
5 | try:
6 | c = a/b
7 | e = d[5]
8 | except ZeroDivisionError:
9 | print("Handel ZeroDivisionError")
10 | except:
11 | print("Handle Error")
12 | else:
13 | print(c)
14 |
15 | print("last")
16 |
17 |
--------------------------------------------------------------------------------
/17Sep2017/exceptions/exceptions12.py:
--------------------------------------------------------------------------------
1 | print("First")
2 | a = 5
3 | b = 5
4 | d = []
5 | try:
6 | c = a/b
7 | #e = d[5]
8 | except ZeroDivisionError:
9 | print("Handel ZeroDivisionError")
10 | except:
11 | print("Handle Error")
12 | else:
13 | print(c)
14 | finally:
15 | print("Finally will always run")
16 |
17 | print("last")
18 |
19 |
--------------------------------------------------------------------------------
/17Sep2017/exceptions/exceptions13.py:
--------------------------------------------------------------------------------
1 | class Student():
2 | def __init__(self,name,age):
3 | if age > 80 or age <16:
4 | raise Exception("Age can not be greater then 80 and less then 16")
5 | self.name = name
6 | self.age = age
7 |
8 | print("before")
9 | st = Student("Hello",600)
10 | print(st.age)
11 |
12 | print("after")
--------------------------------------------------------------------------------
/17Sep2017/exceptions/exceptions14.py:
--------------------------------------------------------------------------------
1 | class Student():
2 | def __init__(self,name,age):
3 | if age > 80:
4 | raise Exception("Age can not be greater then 80")
5 | self.name = name
6 | self.age = age
7 |
8 | print("before")
9 | try:
10 | st = Student("Hello",600)
11 | except Exception as e:
12 | print("Exception "+str(e))
13 | else :
14 | print(st.age)
15 |
16 | print("after")
--------------------------------------------------------------------------------
/17Sep2017/exceptions/exceptions15.py:
--------------------------------------------------------------------------------
1 | class Student():
2 | def __init__(self,name,age):
3 | if age > 80 or age <16:
4 | raise StudentAgeException("Age can not be greater then 80 and less then 16")
5 | self.name = name
6 | self.age = age
7 |
8 | class StudentAgeException(Exception):
9 | pass
10 |
11 | print("before")
12 | st = Student("Hello",600)
13 | print(st.age)
14 |
15 | print("after")
--------------------------------------------------------------------------------
/17Sep2017/exceptions/exceptions16.py:
--------------------------------------------------------------------------------
1 | class Student():
2 | def __init__(self,name,age):
3 | if age > 80 or age <16:
4 | raise StudentAgeException("Age can not be greater then 80 and less then 16")
5 | self.name = name
6 | self.age = age
7 |
8 | class StudentAgeException(Exception):
9 | pass
10 |
11 | print("before")
12 | try:
13 | st = Student("Hello",600)
14 | except StudentAgeException as e:
15 | print("StudentAgeException == "+str(e))
16 | else :
17 | print(st.age)
18 |
19 | print("after")
--------------------------------------------------------------------------------
/17Sep2017/exceptions/exceptions2.py:
--------------------------------------------------------------------------------
1 | print("First")
2 | a = 5
3 | b = 10
4 | try:
5 | c = a/b
6 | print(c)
7 | except ZeroDivisionError:
8 | print("Handle ZeroDivisionError")
9 |
10 |
11 | print("last")
12 |
13 |
--------------------------------------------------------------------------------
/17Sep2017/exceptions/exceptions3.py:
--------------------------------------------------------------------------------
1 | print("First")
2 | a = 5
3 | b = 0
4 | try:
5 | c = a/b
6 | except ZeroDivisionError:
7 | print("Handle ZeroDivisionError")
8 | else:
9 | print(c)
10 |
11 | print("last")
12 |
13 |
--------------------------------------------------------------------------------
/17Sep2017/exceptions/exceptions4.py:
--------------------------------------------------------------------------------
1 | print("First")
2 | a = 5
3 | b = 0
4 | try:
5 | c = a/b
6 | except ZeroDivisionError:
7 | pass
8 | else:
9 | print(c)
10 |
11 | print("last")
12 |
13 |
--------------------------------------------------------------------------------
/17Sep2017/exceptions/exceptions5.py:
--------------------------------------------------------------------------------
1 | print("First")
2 | a = 5
3 | b = 0
4 | d = []
5 | try:
6 | c = a/b
7 | e = d[5]
8 | except ZeroDivisionError:
9 | print("Handle ZeroDivisionError")
10 | else:
11 | print(c)
12 |
13 | print("last")
14 |
15 |
--------------------------------------------------------------------------------
/17Sep2017/exceptions/exceptions6.py:
--------------------------------------------------------------------------------
1 | print("First")
2 | a = 5
3 | b = 5
4 | d = []
5 | try:
6 | c = a/b
7 | e = d[5]
8 | except ZeroDivisionError:
9 | print("Handle ZeroDivisionError")
10 | else:
11 | print(c)
12 |
13 | print("last")
14 |
15 |
--------------------------------------------------------------------------------
/17Sep2017/exceptions/exceptions7.py:
--------------------------------------------------------------------------------
1 | print("First")
2 | a = 5
3 | b = 5
4 | d = []
5 | try:
6 | c = a/b
7 | e = d[5]
8 | except ZeroDivisionError:
9 | print("Handle ZeroDivisionError")
10 | except IndexError:
11 | print("Handle IndexError")
12 | else:
13 | print(c)
14 |
15 | print("last")
16 |
17 |
--------------------------------------------------------------------------------
/17Sep2017/exceptions/exceptions8.py:
--------------------------------------------------------------------------------
1 | print("First")
2 | a = 5
3 | b = 0
4 | d = []
5 | try:
6 | c = a/b
7 | e = d[5]
8 | except:
9 | print("Handle Error")
10 | else:
11 | print(c)
12 |
13 | print("last")
14 |
15 |
--------------------------------------------------------------------------------
/17Sep2017/exceptions/exceptions9.py:
--------------------------------------------------------------------------------
1 | print("First")
2 | a = 5
3 | b = 1
4 | d = []
5 | try:
6 | c = a/b
7 | e = d[5]
8 | except Exception as e:
9 | print("Handle Error == " +str(e))
10 | else:
11 | print(c)
12 |
13 | print("last")
14 |
15 |
--------------------------------------------------------------------------------
/17Sep2017/storingdata/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/17Sep2017/storingdata/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/17Sep2017/storingdata/.idea/storingdata.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/17Sep2017/storingdata/numbers.json:
--------------------------------------------------------------------------------
1 | [2, 3, 5, 7, 11, 13]
--------------------------------------------------------------------------------
/17Sep2017/storingdata/numbers2.json:
--------------------------------------------------------------------------------
1 | {"name": "Qasim", "age": 21}
--------------------------------------------------------------------------------
/17Sep2017/storingdata/numbers3.json:
--------------------------------------------------------------------------------
1 | [2, 3, 5, 7, 11, 13]
--------------------------------------------------------------------------------
/17Sep2017/storingdata/numbers4.json:
--------------------------------------------------------------------------------
1 | 5"hello"true
--------------------------------------------------------------------------------
/17Sep2017/storingdata/q10.py:
--------------------------------------------------------------------------------
1 | def f(n):
2 | if n==0:
3 | return 1
4 | return f(n-1)+100
5 | print(f(5))
--------------------------------------------------------------------------------
/17Sep2017/storingdata/sotring2.py:
--------------------------------------------------------------------------------
1 | import json
2 |
3 | stu = {
4 | "name":"Qasim",
5 | "age": 21
6 | }
7 |
8 | filename = 'numbers2.json'
9 | with open(filename, 'w') as f_obj:
10 | json.dump(stu, f_obj)
--------------------------------------------------------------------------------
/17Sep2017/storingdata/storing1.py:
--------------------------------------------------------------------------------
1 | import json
2 |
3 | numbers = [2, 3, 5, 7, 11, 13]
4 |
5 | filename = 'numbers.json'
6 | with open(filename, 'w') as f_obj:
7 | json.dump(numbers, f_obj)
--------------------------------------------------------------------------------
/17Sep2017/storingdata/storing3.py:
--------------------------------------------------------------------------------
1 | import json
2 |
3 | numbers = [2, 3, 5, 7, 11, 13]
4 |
5 | filename = 'numbers3.json'
6 | with open(filename, 'w') as f_obj:
7 | f_obj.write(str(numbers))
--------------------------------------------------------------------------------
/17Sep2017/storingdata/storing4.py:
--------------------------------------------------------------------------------
1 | a = "[2, 3, 5, 7, 11, 13]"
--------------------------------------------------------------------------------
/17Sep2017/storingdata/storing5.py:
--------------------------------------------------------------------------------
1 | import json
2 |
3 | data = []
4 | filename = 'numbers.json'
5 | with open(filename) as f_obj:
6 | data = json.load(f_obj)
7 |
8 | print(data);
9 | print(data[1]);
--------------------------------------------------------------------------------
/17Sep2017/storingdata/storing6.py:
--------------------------------------------------------------------------------
1 | import json
2 |
3 | stu = {}
4 | filename = 'numbers2.json'
5 | with open(filename) as f_obj:
6 | stu = json.load(f_obj)
7 |
8 | print(stu);
9 | print(stu["name"]);
--------------------------------------------------------------------------------
/17Sep2017/storingdata/storing7.py:
--------------------------------------------------------------------------------
1 | import json
2 |
3 | stu = 5
4 | name = "hello"
5 | filename = 'numbers4.json'
6 | with open(filename,"w") as file_obj:
7 | json.dump(stu,file_obj)
8 | json.dump(name, file_obj)
9 | json.dump(True, file_obj)
10 |
--------------------------------------------------------------------------------
/17Sep2017/storingdata/storing8.py:
--------------------------------------------------------------------------------
1 | import json
2 |
3 | data = 0
4 |
5 | filename = 'numbers4.json'
6 | with open(filename) as file_obj:
7 | data = json.load(file_obj)
8 |
9 | print(data)
10 |
--------------------------------------------------------------------------------
/20Aug2017/DemoDictionaries/.idea/DemoDictionaries.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/20Aug2017/DemoDictionaries/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/20Aug2017/DemoDictionaries/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/20Aug2017/DemoDictionaries/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/20Aug2017/DemoDictionaries/Dictioanry13.py:
--------------------------------------------------------------------------------
1 | studentDictionary = {
2 | 'stu1' : {
3 | 'name':'Qasim',
4 | 'email':'qasim@gmail.com',
5 | 'languages' : ['C#','Python','JavaScript']
6 | },
7 | 'stu2' : {'name':'Inzamam','email':'inzamam@gmail.com',
8 | 'languages': ['C#', 'Java', 'JavaScript']
9 | },
10 | 'stu3' : {'name':'Jaffar','email':'jaffar@gmail.com',
11 | 'languages': ['C#', 'Python', 'PHP']
12 | }
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/20Aug2017/DemoDictionaries/Dictionary1.py:
--------------------------------------------------------------------------------
1 | stu1 = {'name':'Qasim',
2 | 'email':'abc@gmail.com',
3 | 'age':20}
4 | print(stu1)
5 | print(stu1['name'])
6 | print(stu1['age'])
--------------------------------------------------------------------------------
/20Aug2017/DemoDictionaries/Dictionary10.py:
--------------------------------------------------------------------------------
1 | stu1 = {
2 | 'name':'Qasim',
3 | 'email':'qasim@gmail.com',
4 | 'languages' : ['C#','Python','JavaScript']
5 | }
6 | stu2 = {'name':'Inzamam','email':'inzamam@gmail.com',
7 | 'languages': ['C#', 'Java', 'JavaScript']
8 | }
9 | stu3 = {'name':'Jaffar','email':'jaffar@gmail.com',
10 | 'languages': ['C#', 'Python', 'PHP']
11 | }
12 |
13 | students = [stu1,stu2,stu3]
14 |
15 | print(students)
--------------------------------------------------------------------------------
/20Aug2017/DemoDictionaries/Dictionary11.py:
--------------------------------------------------------------------------------
1 | stu1 = {
2 | 'name':'Qasim',
3 | 'email':'qasim@gmail.com',
4 | 'languages' : ['C#','Python','JavaScript']
5 | }
6 | stu2 = {'name':'Inzamam','email':'inzamam@gmail.com',
7 | 'languages': ['C#', 'Java', 'JavaScript']
8 | }
9 | stu3 = {'name':'Jaffar','email':'jaffar@gmail.com',
10 | 'languages': ['C#', 'Python', 'PHP']
11 | }
12 |
13 | students = [stu1,stu2,stu3]
14 | #print(students)
15 |
16 |
17 | for stu in students:
18 | print(stu)
19 | for key,val in stu.items():
20 | print("key: ",key," -- Value : ",val)
21 | if key == 'languages':
22 | for lang in val:
23 | print(lang)
24 | print("")
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/20Aug2017/DemoDictionaries/Dictionary12.py:
--------------------------------------------------------------------------------
1 | stu1 = {
2 | 'name':'Qasim',
3 | 'email':'qasim@gmail.com',
4 | 'languages' : ['C#','Python','JavaScript']
5 | }
6 | stu2 = {'name':'Inzamam','email':'inzamam@gmail.com',
7 | 'languages': ['C#', 'Java', 'JavaScript']
8 | }
9 | stu3 = {'name':'Jaffar','email':'jaffar@gmail.com',
10 | 'languages': ['C#', 'Python', 'PHP']
11 | }
12 |
13 | studentDictionary = {}
14 | studentDictionary['Stu1'] = stu1
15 | studentDictionary['Stu2'] = stu2
16 | studentDictionary['Stu3'] = stu3
17 |
18 |
--------------------------------------------------------------------------------
/20Aug2017/DemoDictionaries/Dictionary13.py:
--------------------------------------------------------------------------------
1 |
2 | val = []
3 | print(type(val))
4 |
5 | responses = {}
6 | polling_active = True
7 | while polling_active:
8 | name = input("\nWhat is your name? ")
9 | response = input("Which mountain would you like to climb someday? ")
10 |
11 | responses[name] = response
12 |
13 | repeat = input("Would you like to let another person respond? (yes/ no) ")
14 | if repeat == 'no':
15 | polling_active = False
16 |
17 |
18 | print("\n--- Poll Results ---")
19 | for name, response in responses.items():
20 | print(name + " would like to climb " + response + ".")
21 |
22 |
23 | val = 45
24 | print(type(val))
--------------------------------------------------------------------------------
/20Aug2017/DemoDictionaries/Dictionary14.py:
--------------------------------------------------------------------------------
1 | '''
2 | Global dictonary
3 | 1) cmp(dic1, dict2)
4 | 2) len(dic)
5 | 3) str(dic)
6 | 4) type(varible)
7 |
8 | Class function
9 |
10 | 1) dic.clear()
11 | 2) dic.copy()
12 | 3) dict.fromkeys()
13 | 4) dic.get(key, defualt=None)
14 | 5) dic.has_key(key)
15 | 6) dic.items()
16 | 7) dic.keys()
17 | 8) dic.values()
18 | 9) dic.setdefualt(key, defualt=None)
19 | 10) dic.update(dic2)
20 | '''
21 |
22 | student ={"name":"Asif","age":20}
23 | print(student)
24 | #student.clear()
25 | #print(student)
26 | print(student.fromkeys())
27 |
--------------------------------------------------------------------------------
/20Aug2017/DemoDictionaries/Dictionary2.py:
--------------------------------------------------------------------------------
1 | stu1 = {'name':'Qasim',
2 | 'email':'abc@gmail.com',
3 | 'age':20,
4 | 23:"hello",
5 | True:"working",
6 | 2.5:"new",
7 | 4:True}
8 | print(stu1)
9 | print(stu1['name'])
10 | print(stu1['age'])
11 | print(stu1[23])
12 | print(stu1[4])
--------------------------------------------------------------------------------
/20Aug2017/DemoDictionaries/Dictionary5.py:
--------------------------------------------------------------------------------
1 | stu1 = {'name':'Qasim',
2 | 'email':'abc@gmail.com',
3 | 'age':20,
4 | 23:"hello",
5 | True:"working",
6 | 2.5:"new",
7 | 4:True}
8 | print(stu1)
9 | print(stu1.values())
10 | for value in stu1.values():
11 | #print("\nKey: ", key)
12 | print("Value: ", value)
13 |
14 |
15 |
--------------------------------------------------------------------------------
/20Aug2017/DemoDictionaries/Dictionary6.py:
--------------------------------------------------------------------------------
1 | favorite_languages = {
2 | 'jen': 'python',
3 | 'sarah': 'c',
4 | 'edward': 'ruby',
5 | 'phil': 'python',
6 | }
7 | for name in sorted(favorite_languages.keys()):
8 | print(name.title() + ", thank you for taking the poll.")
--------------------------------------------------------------------------------
/20Aug2017/DemoDictionaries/Dictionary7.py:
--------------------------------------------------------------------------------
1 | favorite_languages = {
2 | 'jen': 'python',
3 | 'sarah': 'c',
4 | 'edward': 'ruby',
5 | 'phil': 'python',
6 | }
7 | for language in set(favorite_languages.values()):
8 | print(language.title())
--------------------------------------------------------------------------------
/20Aug2017/DemoDictionaries/Dictionary8.py:
--------------------------------------------------------------------------------
1 | a={"Qasim","Zeeshan","Zeeshan"}
2 | print(a)
--------------------------------------------------------------------------------
/20Aug2017/DemoDictionaries/Dictionary9.py:
--------------------------------------------------------------------------------
1 | stu1 = {'name':'Qasim','email':'qasim@gmail.com'}
2 | stu2 = {'name':'Inzamam','email':'inzamam@gmail.com'}
3 | stu3 = {'name':'Jaffar','email':'jaffar@gmail.com'}
4 |
5 | students = [stu1,stu2,stu3]
6 | students = []
7 | students.append(stu1)
8 | students.append(stu2)
9 | students.append(stu3)
--------------------------------------------------------------------------------
/20Aug2017/DemoDictionaries/Distionary3.py:
--------------------------------------------------------------------------------
1 | stu1 = {'name':'Qasim',
2 | 'email':'abc@gmail.com',
3 | 'age':20,
4 | 23:"hello",
5 | True:"working",
6 | 2.5:"new",
7 | 4:True}
8 | print(stu1)
9 | print(stu1['name'])
10 | stu1['name'] = 'Inzamam'
11 | print(stu1['name'])
--------------------------------------------------------------------------------
/20Aug2017/DemoDictionaries/Distionary4.py:
--------------------------------------------------------------------------------
1 | stu1 = {'name':'Qasim',
2 | 'email':'abc@gmail.com',
3 | 'age':20,
4 | 23:"hello",
5 | True:"working",
6 | 2.5:"new",
7 | 4:True}
8 | print(stu1)
9 | print(stu1.items())
10 | for key, value in stu1.items():
11 | print("\nKey: ", key)
12 | print("Value: ", value)
13 |
14 |
15 |
16 |
17 | name, fname =("Qasim", "Aslam")
18 | print(name)
19 |
20 |
21 |
--------------------------------------------------------------------------------
/20Aug2017/Functions/.idea/Functions.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/20Aug2017/Functions/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/20Aug2017/Functions/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/20Aug2017/Functions/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/20Aug2017/Functions/Func1.py:
--------------------------------------------------------------------------------
1 | def greet_user():
2 | print("Hello World")
3 | print("Hello World 2")
4 |
5 | greet_user()
--------------------------------------------------------------------------------
/20Aug2017/Functions/Func10.py:
--------------------------------------------------------------------------------
1 | def fayyaz(itemList):
2 | for i in itemList:
3 | print("Buying "+i)
4 |
5 | myItems = ["Briyani","Anday wala burger","Nihari","Lassi"]
6 | fayyaz(myItems)
--------------------------------------------------------------------------------
/20Aug2017/Functions/Func11.py:
--------------------------------------------------------------------------------
1 | def fayyaz(itemList):
2 | itemList[0] = "Pulaoo"
3 | for i in itemList:
4 | print("Buying "+i)
5 |
6 | myItems = ["Briyani","Anday wala burger","Nihari","Lassi"]
7 | print(myItems)
8 | fayyaz(myItems[:])
9 | print(myItems)
--------------------------------------------------------------------------------
/20Aug2017/Functions/Func12.py:
--------------------------------------------------------------------------------
1 | def fayyaz(*itemList):
2 | #itemList[0] = "Pulaoo"
3 | for i in itemList:
4 | print("Buying "+i)
5 |
6 | fayyaz("Briyani","Anday wala burger","Nihari","Lassi")
7 | #print(myItems)
--------------------------------------------------------------------------------
/20Aug2017/Functions/Func13.py:
--------------------------------------------------------------------------------
1 | def fayyaz(**itemList):
2 | #itemList[0] = "Pulaoo"
3 | for i,j in itemList.items():
4 | print("Buying "+i)
5 | print(j)
6 |
7 |
8 | fayyaz(rice=2,coke=5)
9 | #print(myItems)
--------------------------------------------------------------------------------
/20Aug2017/Functions/Func2.py:
--------------------------------------------------------------------------------
1 | def fayyaz():
2 | print("Make Tea")
3 | print("Add sugar 2 spoon")
4 | print("Add 1 Tea bag")
5 | print("Fill cup")
6 |
7 | fayyaz()
8 | fayyaz()
9 | fayyaz()
10 | fayyaz()
--------------------------------------------------------------------------------
/20Aug2017/Functions/Func3.py:
--------------------------------------------------------------------------------
1 | def fayyaz(noOfCups, sugar):
2 | print("Make Tea")
3 | print("Preparing "+str(noOfCups)+" cups of Tea")
4 | print("Adding sugar "+str(sugar)+" spoon")
5 | print("Add 1 Tea bag")
6 | print("Fill cup")
7 |
8 | fayyaz(2,3)
--------------------------------------------------------------------------------
/20Aug2017/Functions/Func4.py:
--------------------------------------------------------------------------------
1 | def fayyaz(noOfCups, sugar):
2 | print("Make Tea")
3 | print("Preparing "+str(noOfCups)+" cups of Tea")
4 | print("Adding sugar "+str(sugar)+" spoon")
5 | print("Add 1 Tea bag")
6 | print("Fill cup")
7 |
8 | fayyaz(sugar=3,noOfCups=2)
--------------------------------------------------------------------------------
/20Aug2017/Functions/Func5.py:
--------------------------------------------------------------------------------
1 | def fayyaz(noOfCups, sugar):
2 | print("Make Tea")
3 | print("Preparing "+str(noOfCups)+" cups of Tea")
4 | print("Adding sugar "+str(sugar)+" spoon")
5 | print("Add 1 Tea bag")
6 | print("Fill cup")
7 |
8 | fayyaz(2,sugar=3)
--------------------------------------------------------------------------------
/20Aug2017/Functions/Func6.py:
--------------------------------------------------------------------------------
1 | def fayyaz(noOfCups, sugar=2):
2 | print("Make Tea")
3 | print("Preparing "+str(noOfCups)+" cups of Tea")
4 | print("Adding sugar "+str(sugar)+" spoon")
5 | print("Add 1 Tea bag")
6 | print("Fill cup")
7 |
8 | fayyaz(4)
9 | fayyaz(4,3)
10 | fayyaz(4,sugar=3)
11 | fayyaz(sugar=3,noOfCups=3)
12 | fayyaz(noOfCups=3)
--------------------------------------------------------------------------------
/20Aug2017/Functions/Func7.py:
--------------------------------------------------------------------------------
1 | def fayyaz(noOfCups, sugar=2):
2 | print("Make Tea")
3 | print("Preparing "+str(noOfCups)+" cups of Tea")
4 | print("Adding sugar "+str(sugar)+" spoon")
5 | print("Add 1 Tea bag")
6 | print("Fill cup")
7 | return str(noOfCups)+" cup of Tea"
8 |
9 |
10 | collectTea = fayyaz(4)
11 | print(collectTea)
12 |
13 |
--------------------------------------------------------------------------------
/20Aug2017/Functions/Func8.py:
--------------------------------------------------------------------------------
1 | def fayyaz(noOfCups, sugar=2,elichi=''):
2 | print("Make Tea")
3 | print("Preparing "+str(noOfCups)+" cups of Tea")
4 | print("Adding sugar "+str(sugar)+" spoon")
5 | if(elichi=='yes'):
6 | print("Adding Elichi")
7 | print("Add 1 Tea bag")
8 | print("Fill cup")
9 | return str(noOfCups)+" cup of Tea"
10 |
11 |
12 | collectTea = fayyaz(4,elichi="yes")
13 | print(collectTea)
14 |
15 |
--------------------------------------------------------------------------------
/20Aug2017/Functions/Func9.py:
--------------------------------------------------------------------------------
1 | def fayyaz(noOfCups, sugar=2,elichi=''):
2 | print("Make Tea")
3 | print("Preparing "+str(noOfCups)+" cups of Tea")
4 | print("Adding sugar "+str(sugar)+" spoon")
5 | if(elichi=='yes'):
6 | print("Adding Elichi")
7 | print("Add 1 Tea bag")
8 | print("Fill cup")
9 | return {"Cups":noOfCups,"sugar":sugar,"elichi":elichi}
10 |
11 |
12 | collectTea = fayyaz(4,elichi="yes")
13 | print(collectTea)
14 |
15 |
--------------------------------------------------------------------------------
/22Oct2017/datascience_chap1/.idea/datascience_chap1.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/22Oct2017/datascience_chap1/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/22Oct2017/datascience_chap1/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/22Oct2017/datascience_chap1/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 | 1508665014924
264 |
265 |
266 | 1508665014924
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
--------------------------------------------------------------------------------
/22Oct2017/datascience_chap1/demo1.py:
--------------------------------------------------------------------------------
1 | users = [
2 | { "id": 0, "name": "Hero" },
3 | { "id": 1, "name": "Dunn" },
4 | { "id": 2, "name": "Sue" },
5 | { "id": 3, "name": "Chi" },
6 | { "id": 4, "name": "Thor" },
7 | { "id": 5, "name": "Clive" },
8 | { "id": 6, "name": "Hicks" },
9 | { "id": 7, "name": "Devin" },
10 | { "id": 8, "name": "Kate" },
11 | { "id": 9, "name": "Klein" }
12 | ]
13 |
14 | friendships = [(0, 1), (0, 2), (1, 2), (1, 3), (2, 3), (3, 4),
15 | (4, 5), (5, 6), (5, 7), (6, 8), (7, 8), (8, 9)]
16 |
17 | for user in users:
18 | user["friends"] = []
19 |
20 | for i, j in friendships:
21 | # this works because users[i] is the user whose id is i
22 | users[i]["friends"].append(users[j]) # add i as a friend of j
23 | users[j]["friends"].append(users[i]) # add j as a friend of i
24 | def number_of_friends(user):
25 | """how many friends does _user_ have?"""
26 | return len(user["friends"])
27 |
28 | data=[number_of_friends(user)
29 | for user in users]
30 |
31 |
32 | print(sum(data))
--------------------------------------------------------------------------------
/22Oct2017/datascience_chap1/demo2.py:
--------------------------------------------------------------------------------
1 | users = [
2 | { "id": 0, "name": "Hero" },
3 | { "id": 1, "name": "Dunn" },
4 | { "id": 2, "name": "Sue" },
5 | { "id": 3, "name": "Chi" },
6 | { "id": 4, "name": "Thor" },
7 | { "id": 5, "name": "Clive" },
8 | { "id": 6, "name": "Hicks" },
9 | { "id": 7, "name": "Devin" },
10 | { "id": 8, "name": "Kate" },
11 | { "id": 9, "name": "Klein" }
12 | ]
13 |
14 | friendships = [(0, 1), (0, 2), (1, 2), (1, 3), (2, 3), (3, 4),
15 | (4, 5), (5, 6), (5, 7), (6, 8), (7, 8), (8, 9)]
16 |
17 | for user in users:
18 | user["friends"] = []
19 |
20 | for i, j in friendships:
21 | # this works because users[i] is the user whose id is i
22 | users[i]["friends"].append(users[j]) # add i as a friend of j
23 | users[j]["friends"].append(users[i]) # add j as a friend of i
24 | def number_of_friends(user):
25 | """how many friends does _user_ have?"""
26 | return len(user["friends"])
27 |
28 | total_connections = sum(number_of_friends(user)
29 | for user in users)
30 |
31 | num_users = len(users) # length of the users list
32 | avg_connections = total_connections / num_users
33 |
34 | print(num_users)
35 | print(avg_connections)
--------------------------------------------------------------------------------
/22Oct2017/datascience_chap1/demo3.py:
--------------------------------------------------------------------------------
1 | users = [
2 | { "id": 0, "name": "Hero" },
3 | { "id": 1, "name": "Dunn" },
4 | { "id": 2, "name": "Sue" },
5 | { "id": 3, "name": "Chi" },
6 | { "id": 4, "name": "Thor" },
7 | { "id": 5, "name": "Clive" },
8 | { "id": 6, "name": "Hicks" },
9 | { "id": 7, "name": "Devin" },
10 | { "id": 8, "name": "Kate" },
11 | { "id": 9, "name": "Klein" }
12 | ]
13 |
14 | friendships = [(0, 1), (0, 2), (1, 2), (1, 3), (2, 3), (3, 4),
15 | (4, 5), (5, 6), (5, 7), (6, 8), (7, 8), (8, 9)]
16 |
17 | for user in users:
18 | user["friends"] = []
19 |
20 | for i, j in friendships:
21 | # this works because users[i] is the user whose id is i
22 | users[i]["friends"].append(users[j]) # add i as a friend of j
23 | users[j]["friends"].append(users[i]) # add j as a friend of i
24 | def number_of_friends(user):
25 | """how many friends does _user_ have?"""
26 | return len(user["friends"])
27 |
28 | total_connections = sum(number_of_friends(user)
29 | for user in users)
30 |
31 | num_users = len(users) # length of the users list
32 | avg_connections = total_connections / num_users
33 |
34 | # create a list (user_id, number_of_friends)
35 | num_friends_by_id = [(user["id"], number_of_friends(user))
36 | for user in users]
37 | print(sorted(num_friends_by_id, key= lambda data: data[1], reverse=True))
38 |
39 | # print(sorted(num_friends_by_id, reverse=True))
--------------------------------------------------------------------------------
/22Oct2017/datascience_chap1/demo4.py:
--------------------------------------------------------------------------------
1 | users = [
2 | { "id": 0, "name": "Hero" },
3 | { "id": 1, "name": "Dunn" },
4 | { "id": 2, "name": "Sue" },
5 | { "id": 3, "name": "Chi" },
6 | { "id": 4, "name": "Thor" },
7 | { "id": 5, "name": "Clive" },
8 | { "id": 6, "name": "Hicks" },
9 | { "id": 7, "name": "Devin" },
10 | { "id": 8, "name": "Kate" },
11 | { "id": 9, "name": "Klein" }
12 | ]
13 |
14 | friendships = [(0, 1), (0, 2), (1, 2), (1, 3), (2, 3), (3, 4),
15 | (4, 5), (5, 6), (5, 7), (6, 8), (7, 8), (8, 9)]
16 |
17 | for user in users:
18 | user["friends"] = []
19 |
20 | for i, j in friendships:
21 | # this works because users[i] is the user whose id is i
22 | users[i]["friends"].append(users[j]) # add i as a friend of j
23 | users[j]["friends"].append(users[i]) # add j as a friend of i
24 |
25 |
26 | def friends_of_friend_ids_bad(user):
27 | # "foaf" is short for "friend of a friend"
28 | return [foaf["id"]
29 | for friend in user["friends"] # for each of user's friends
30 | for foaf in friend["friends"]] #
31 |
32 | print(friends_of_friend_ids_bad(users[0]))
33 | foafList = [friends_of_friend_ids_bad(user) for user in users]
34 | print(foafList)
35 |
--------------------------------------------------------------------------------
/22Oct2017/datascience_chap1/demo5.py:
--------------------------------------------------------------------------------
1 | users = [
2 | { "id": 0, "name": "Hero" },
3 | { "id": 1, "name": "Dunn" },
4 | { "id": 2, "name": "Sue" },
5 | { "id": 3, "name": "Chi" },
6 | { "id": 4, "name": "Thor" },
7 | { "id": 5, "name": "Clive" },
8 | { "id": 6, "name": "Hicks" },
9 | { "id": 7, "name": "Devin" },
10 | { "id": 8, "name": "Kate" },
11 | { "id": 9, "name": "Klein" }
12 | ]
13 |
14 | friendships = [(0, 1), (0, 2), (1, 2), (1, 3), (2, 3), (3, 4),
15 | (4, 5), (5, 6), (5, 7), (6, 8), (7, 8), (8, 9)]
16 |
17 | for user in users:
18 | user["friends"] = []
19 |
20 | for i, j in friendships:
21 | # this works because users[i] is the user whose id is i
22 | users[i]["friends"].append(users[j]) # add i as a friend of j
23 | users[j]["friends"].append(users[i]) # add j as a friend of i
24 |
25 |
26 | def friends_of_friend_ids_bad(user):
27 | # "foaf" is short for "friend of a friend"
28 | return [foaf["id"]
29 | for friend in user["friends"] # for each of user's friends
30 | for foaf in friend["friends"]] #
31 |
32 | def not_the_same(user, other_user):
33 | """two users are not the same if they have different ids"""
34 | return user["id"] != other_user["id"]
35 |
36 | print(not_the_same(users[0],users[1]))
37 |
--------------------------------------------------------------------------------
/22Oct2017/datascience_chap1/demo6.py:
--------------------------------------------------------------------------------
1 | users = [
2 | { "id": 0, "name": "Hero" },
3 | { "id": 1, "name": "Dunn" },
4 | { "id": 2, "name": "Sue" },
5 | { "id": 3, "name": "Chi" },
6 | { "id": 4, "name": "Thor" },
7 | { "id": 5, "name": "Clive" },
8 | { "id": 6, "name": "Hicks" },
9 | { "id": 7, "name": "Devin" },
10 | { "id": 8, "name": "Kate" },
11 | { "id": 9, "name": "Klein" }
12 | ]
13 |
14 | friendships = [(0, 1), (0, 2), (1, 2), (1, 3), (2, 3), (3, 4),
15 | (4, 5), (5, 6), (5, 7), (6, 8), (7, 8), (8, 9)]
16 |
17 | for user in users:
18 | user["friends"] = []
19 |
20 | for i, j in friendships:
21 | # this works because users[i] is the user whose id is i
22 | users[i]["friends"].append(users[j]) # add i as a friend of j
23 | users[j]["friends"].append(users[i]) # add j as a friend of i
24 |
25 |
26 | def friends_of_friend_ids_bad(user):
27 | # "foaf" is short for "friend of a friend"
28 | return [foaf["id"]
29 | for friend in user["friends"] # for each of user's friends
30 | for foaf in friend["friends"]] #
31 |
32 | def not_the_same(user, other_user):
33 | """two users are not the same if they have different ids"""
34 | return user["id"] != other_user["id"]
35 |
36 |
37 | def not_friends(user, other_user):
38 | """other_user is not a friend if he's not in user["friends"];
39 | that is, if he's not_the_same as all the people in user["friends"]"""
40 | return all(not_the_same(friend, other_user)
41 | for friend in user["friends"])
42 |
43 | print(not_friends(users[0],users[3]))
44 |
--------------------------------------------------------------------------------
/22Oct2017/datascience_chap1/demo7.py:
--------------------------------------------------------------------------------
1 | users = [
2 | { "id": 0, "name": "Hero" },
3 | { "id": 1, "name": "Dunn" },
4 | { "id": 2, "name": "Sue" },
5 | { "id": 3, "name": "Chi" },
6 | { "id": 4, "name": "Thor" },
7 | { "id": 5, "name": "Clive" },
8 | { "id": 6, "name": "Hicks" },
9 | { "id": 7, "name": "Devin" },
10 | { "id": 8, "name": "Kate" },
11 | { "id": 9, "name": "Klein" }
12 | ]
13 |
14 | friendships = [(0, 1), (0, 2), (1, 2), (1, 3), (2, 3), (3, 4),
15 | (4, 5), (5, 6), (5, 7), (6, 8), (7, 8), (8, 9)]
16 |
17 | for user in users:
18 | user["friends"] = []
19 |
20 | for i, j in friendships:
21 | # this works because users[i] is the user whose id is i
22 | users[i]["friends"].append(users[j]) # add i as a friend of j
23 | users[j]["friends"].append(users[i]) # add j as a friend of i
24 |
25 |
26 | def friends_of_friend_ids_bad(user):
27 | # "foaf" is short for "friend of a friend"
28 | return [foaf["id"]
29 | for friend in user["friends"] # for each of user's friends
30 | for foaf in friend["friends"]] #
31 |
32 | def not_the_same(user, other_user):
33 | """two users are not the same if they have different ids"""
34 | return user["id"] != other_user["id"]
35 |
36 |
37 | def not_friends(user, other_user):
38 | """other_user is not a friend if he's not in user["friends"];
39 | that is, if he's not_the_same as all the people in user["friends"]"""
40 | return all(not_the_same(friend, other_user)
41 | for friend in user["friends"])
42 |
43 | from collections import Counter
44 |
45 | def friends_of_friend_ids(user):
46 | return Counter(foaf["id"]
47 | for friend in user["friends"]
48 | for foaf in friend["friends"]
49 | if not_the_same(user, foaf)
50 | and not_friends(user, foaf)) # and aren't my friends
51 |
52 | print(friends_of_friend_ids(users[0]))
--------------------------------------------------------------------------------
/23July2017/hello/.idea/hello.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/23July2017/hello/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/23July2017/hello/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/23July2017/hello/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/23July2017/hello/eight.py:
--------------------------------------------------------------------------------
1 | num1 = 0.1
2 | num2 = 0.2
3 | print(num1 + num2)
4 | print(num1 - num2)
5 | print(num1 * num2)
6 | num3 = 5
7 | #print(num3)
8 |
--------------------------------------------------------------------------------
/23July2017/hello/fifth.py:
--------------------------------------------------------------------------------
1 | name = " hello world "
2 | name = name.strip()
3 | name = name.title()
4 |
5 | name1 = name.strip()
6 | name2 = name1.title()
7 | print(name2)
8 |
9 |
--------------------------------------------------------------------------------
/23July2017/hello/first.py:
--------------------------------------------------------------------------------
1 | print("Hello New world")
2 |
3 | name = "Mughal"
4 | name = 'Mughal'
5 | age = 45
6 | email = "zeeshanhanif@gmail.com"
7 | print(name)
8 | name = 67
9 | print(name)
10 |
11 | name1 = "My father\"s name is M. Aslam"
12 | print(name1)
13 |
14 |
15 |
--------------------------------------------------------------------------------
/23July2017/hello/forth.py:
--------------------------------------------------------------------------------
1 | languages = "Languages:\n\tPython\n\tC\n\tJavaScript"
2 | print(languages)
3 |
4 | name = " Hello World "
5 | print(name)
6 | print(name.rstrip())
7 | print(name.lstrip())
8 | print(name.strip())
9 | print(name)
--------------------------------------------------------------------------------
/23July2017/hello/second.py:
--------------------------------------------------------------------------------
1 | name = "qasim"
2 | name1 = name.title()
3 | print(name)
4 | print(name1)
5 | print(name.title())
6 | print(name.upper())
7 | print(name.lower())
8 | print(name)
--------------------------------------------------------------------------------
/23July2017/hello/seventh.py:
--------------------------------------------------------------------------------
1 | num1 = 81
2 | num2 = 3
3 |
4 | print(num1 + num2)
5 | print(num1 - num2)
6 | print(num1 / num2)
7 | print(num1 * num2)
8 | print(num1 % num2)
9 | print(num1 ** num2)
10 | print(num1 // num2)
11 |
12 |
13 | num3 = 5 - 3 * 2 + 2 / 2
14 | print(num3)
--------------------------------------------------------------------------------
/23July2017/hello/sixth.py:
--------------------------------------------------------------------------------
1 | name = " hello world "
2 | print(name.strip().title())
--------------------------------------------------------------------------------
/23July2017/hello/third.py:
--------------------------------------------------------------------------------
1 | firstName = "Qasim"
2 | lastName = "M. Aslam"
3 | age = 45
4 |
5 | fullName = firstName +" "+ lastName
6 | print(firstName)
7 | print(lastName)
8 | print(fullName)
9 | print(firstName,lastName)
10 |
11 | fullName1 = firstName + " " + lastName +" " +str(age)
12 | print(fullName1)
13 |
14 |
--------------------------------------------------------------------------------
/24Sep2017/datascience_chap2/.idea/datascience_chap2.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/24Sep2017/datascience_chap2/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/24Sep2017/datascience_chap2/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/24Sep2017/datascience_chap2/abc.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": null,
6 | "metadata": {
7 | "collapsed": true
8 | },
9 | "outputs": [],
10 | "source": [
11 | "for i in [1, 2, 3, 4, 5]:\n",
12 | "\n",
13 | " # notice the blank line\n",
14 | " print (i)"
15 | ]
16 | }
17 | ],
18 | "metadata": {
19 | "kernelspec": {
20 | "display_name": "Python 2",
21 | "language": "python",
22 | "name": "python2"
23 | },
24 | "language_info": {
25 | "codemirror_mode": {
26 | "name": "ipython",
27 | "version": 2
28 | },
29 | "file_extension": ".py",
30 | "mimetype": "text/x-python",
31 | "name": "python",
32 | "nbconvert_exporter": "python",
33 | "pygments_lexer": "ipython2",
34 | "version": "2.7.6"
35 | }
36 | },
37 | "nbformat": 4,
38 | "nbformat_minor": 0
39 | }
40 |
--------------------------------------------------------------------------------
/24Sep2017/datascience_chap2/demo1.py:
--------------------------------------------------------------------------------
1 | two_plus_three = 2 + \
2 | 3
3 | print(two_plus_three)
4 |
5 | name =" Muhammad " \
6 | "Qasim"
7 | print(name)
8 |
9 | details ="""" Q
10 | Muhammd Qasim
11 | Muhammd Aslam
12 | """
13 |
14 | print(details)
--------------------------------------------------------------------------------
/24Sep2017/datascience_chap2/demo10.py:
--------------------------------------------------------------------------------
1 | word_count = {
2 | "hello":4,
3 | "world":6,
4 | "bye":1,
5 | "working":3
6 | }
7 | x = sorted(word_count.items())
8 | y = sorted(word_count.values())
9 |
10 | z = sorted(word_count.items(), key= [lambda a,b:b])
11 | print(x)
12 | print(y)
13 | print(z)
14 |
--------------------------------------------------------------------------------
/24Sep2017/datascience_chap2/demo2.py:
--------------------------------------------------------------------------------
1 | for i in [1, 2, 3, 4, 5]:
2 |
3 | # notice the blank line
4 | print (i)
--------------------------------------------------------------------------------
/24Sep2017/datascience_chap2/demo3.py:
--------------------------------------------------------------------------------
1 | mylist = (2,94,14)
2 |
3 | a, b, c = mylist
4 |
5 | print(mylist)
6 | print(a)
7 | print(b)
8 | print(c)
--------------------------------------------------------------------------------
/24Sep2017/datascience_chap2/demo4.py:
--------------------------------------------------------------------------------
1 | def sum_and_product(x, y):
2 | return (x + y),(x * y), (x*y)
3 |
4 | sp = sum_and_product(2, 3) # equals (5, 6)
5 | s, p,t = sum_and_product(5, 10) # s is 15, p is 50
6 |
7 | print(sp)
8 | print(s)
9 | print(p)
10 | print(t)
--------------------------------------------------------------------------------
/24Sep2017/datascience_chap2/demo5.py:
--------------------------------------------------------------------------------
1 | from collections import Counter
2 | c = Counter([0, 1, 2, 0])
3 | print(c)
4 | mostCommon = c.most_common(1)
5 | print(mostCommon)
6 |
7 | a,b = mostCommon[0]
8 | print(a)
9 | print(b)
10 |
--------------------------------------------------------------------------------
/24Sep2017/datascience_chap2/demo6.py:
--------------------------------------------------------------------------------
1 | x = 11
2 | y = 21
3 | parity = "even" if x % 2 == 0 else "odd"
4 | print(parity)
5 |
6 | parity2 = "even" if x % 2 == 0 else "y even" if y % 2 == 0 else "y odd"
7 | print(parity2)
--------------------------------------------------------------------------------
/24Sep2017/datascience_chap2/demo7.py:
--------------------------------------------------------------------------------
1 | v = [45,47]
2 |
3 | if v:
4 | print("its true")
5 | else:
6 | print("its false")
--------------------------------------------------------------------------------
/24Sep2017/datascience_chap2/demo8.py:
--------------------------------------------------------------------------------
1 | print(all(["",True, 1, { 3 }]))
2 |
3 |
--------------------------------------------------------------------------------
/24Sep2017/datascience_chap2/demo9.py:
--------------------------------------------------------------------------------
1 | x = sorted([-4,1,-2,3], key=abs, reverse=True)
2 | print(x)
--------------------------------------------------------------------------------
/27Aug2017/Objects/.idea/Objects.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/27Aug2017/Objects/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/27Aug2017/Objects/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/27Aug2017/Objects/object3.py:
--------------------------------------------------------------------------------
1 | class Dog():
2 | """A simple attempt to model a dog."""
3 |
4 | def __init__(self,name,age):
5 | print("Dog init")
6 | print("Name ",name)
7 | print("Age ", age)
8 | self.name = name
9 | self.age = age
10 |
11 | def bark(self):
12 | print(self.name +" is barking")
13 |
14 | e = Dog("willie",6)
15 | e.bark()
--------------------------------------------------------------------------------
/27Aug2017/Objects/objects1.py:
--------------------------------------------------------------------------------
1 | class Dog():
2 | """A simple attempt to model a dog."""
3 |
4 | def __init__(self,name,age):
5 | print("Dog init")
6 | print("Name ",name)
7 | print("Age ", age)
8 |
9 | #def __init__(self,name):
10 | # print("Dog init")
11 | # print("Name ",name)
12 |
13 | def bark(self):
14 | print("Dog is barking")
15 |
16 | e = Dog("willie",6)
17 | #g = Dog("willie")
18 | #print(d)
19 | #d.bark()
20 |
--------------------------------------------------------------------------------
/27Aug2017/Objects/objects10.py:
--------------------------------------------------------------------------------
1 | class Car():
2 |
3 | def __init__(self,make,model,year):
4 | self.make = make
5 | self.model = model
6 | self.year = year
7 | self.__odometer_reading = 5
8 |
9 |
10 | def get_descriptive_name(self):
11 | long_name = str(self.year)+ ' '+self.make + ' ' + self.model + ' '+ str(self.__odometer_reading)
12 | return long_name
13 |
14 | def update_odometer(self, val):
15 | self.__odometer_reading = val
16 |
17 | def get_odometer(self):
18 | return self.__odometer_reading
19 |
20 |
21 | c = Car('audi', 'a4', 2016)
22 |
23 | print(c.get_odometer())
24 | c.update_odometer(400000)
25 | print(c.get_odometer())
26 |
27 |
28 |
--------------------------------------------------------------------------------
/27Aug2017/Objects/objects11.py:
--------------------------------------------------------------------------------
1 | class Car():
2 |
3 | def __init__(self,make,model,year):
4 | self.make = make
5 | self.model = model
6 | self.year = year
7 | self.__odometer_reading = 5
8 |
9 |
10 | def get_descriptive_name(self):
11 | long_name = str(self.year)+ ' '+self.make + ' ' + self.model + ' '+ str(self.__odometer_reading)
12 | return long_name
13 |
14 | def update_odometer(self, val):
15 | self.__odometer_reading = val
16 |
17 | def get_odometer(self):
18 | return self.__odometer_reading
19 |
20 | def __start(self):
21 | print("Car started")
22 |
23 |
24 | c = Car('audi', 'a4', 2016)
25 |
26 | c.__start()
27 |
--------------------------------------------------------------------------------
/27Aug2017/Objects/objects12.py:
--------------------------------------------------------------------------------
1 | class Car():
2 |
3 | def __init__(self,make,model,year):
4 | self.make = make
5 | self.model = model
6 | self.year = year
7 |
8 |
9 | def get_descriptive_name(self):
10 | long_name = str(self.year)+ ' '+self.make + ' ' + self.model
11 | return long_name
12 |
13 | def __str__(self):
14 | return "Make = "+self.make + ", Model = " + self.model + ", Year = "+ str(self.year)
15 |
16 | c = Car('audi', 'a4', 2016)
17 |
18 | print(c)
19 |
--------------------------------------------------------------------------------
/27Aug2017/Objects/objects13.py:
--------------------------------------------------------------------------------
1 | class Car():
2 |
3 | def __init__(self,make,model,year):
4 | self.make = make
5 | self.model = model
6 | self.year = year
7 | self.__odometer_reading = 5
8 |
9 |
10 | def get_descriptive_name(self):
11 | long_name = str(self.year)+ ' '+self.make + ' ' + self.model + ' '+ str(self.__odometer_reading)
12 | return long_name
13 |
14 | def update_odometer(self, val):
15 | self.__odometer_reading = val
16 |
17 | def get_odometer(self):
18 | return self.__odometer_reading
19 |
20 | def __start(self):
21 | print("Car started")
22 |
23 | class ElectricCar(Car):
24 | '''ElectricCar'''
25 | def __init__(self,make,model,year):
26 | super().__init__(make,model,year)
27 | #self.make = make
28 | #self.model = model
29 | #self.year = year
30 |
31 |
32 | c = Car('audi', 'a4', 2016)
33 | ec = ElectricCar('Tesla', 's4', 2016)
34 | print(ec.get_descriptive_name())
35 | print(ec.year)
--------------------------------------------------------------------------------
/27Aug2017/Objects/objects14.py:
--------------------------------------------------------------------------------
1 | class Car():
2 |
3 | def __init__(self,make,model,year):
4 | self.make = make
5 | self.model = model
6 | self.year = year
7 | self.__odometer_reading = 5
8 |
9 |
10 | def get_descriptive_name(self):
11 | #long_name = str(self.year)+ ' '+self.make + ' ' + self.model + ' '+ str(self.__odometer_reading)
12 | long_name = str(self.year) + ' ' + self.make + ' ' + self.model
13 | return long_name
14 |
15 | def update_odometer(self, val):
16 | self.__odometer_reading = val
17 |
18 | def get_odometer(self):
19 | return self.__odometer_reading
20 |
21 | def __start(self):
22 | print("Car started")
23 |
24 | class ElectricCar(Car):
25 | '''ElectricCar'''
26 | def __init__(self,make,model,year):
27 | #super().__init__(make,model,year)
28 | self.make = make
29 | self.model = model
30 | self.year = year
31 |
32 |
33 | c = Car('audi', 'a4', 2016)
34 | ec = ElectricCar('Tesla', 's4', 2016)
35 | print(ec.get_descriptive_name())
36 |
--------------------------------------------------------------------------------
/27Aug2017/Objects/objects2.py:
--------------------------------------------------------------------------------
1 | class Dog():
2 | """A simple attempt to model a dog."""
3 |
4 | def __init__(self,name,age):
5 | print("Dog init")
6 | print("Name ",name)
7 | print("Age ", age)
8 | self.name = name
9 | self.age = age
10 |
11 | def bark(self):
12 | print("Dog is barking")
13 |
14 | e = Dog("willie",6)
15 |
16 | print(e.name)
17 | print(e.age)
18 | e.age = 10
19 | print(e.age)
20 |
--------------------------------------------------------------------------------
/27Aug2017/Objects/objects4.py:
--------------------------------------------------------------------------------
1 | class Dog():
2 | """A simple attempt to model a dog."""
3 |
4 | def __init__(self,name,age):
5 | print("Dog init")
6 | print("Name ",name)
7 | print("Age ", age)
8 | self.name = name
9 | self.age = age
10 |
11 | def bark(self):
12 | print(self.name +" is barking")
13 |
14 | myDog = Dog("willie",6)
15 | yourDog = Dog("lucy",3)
16 |
17 | myDog.bark()
18 | yourDog.bark()
19 |
--------------------------------------------------------------------------------
/27Aug2017/Objects/objects5.py:
--------------------------------------------------------------------------------
1 | class Dog():
2 | """A simple attempt to model a dog."""
3 | total = 0
4 | def __init__(self,name,age):
5 | print("Dog init")
6 | print("Name ",name)
7 | print("Age ", age)
8 | self.name = name
9 | self.age = age
10 | Dog.total = Dog.total+1
11 |
12 | def bark(self):
13 | print(self.name +" is barking")
14 |
15 | myDog = Dog("willie",6)
16 | yourDog = Dog("lucy",3)
17 |
18 | myDog.bark()
19 | yourDog.bark()
20 | print(Dog.total)
21 |
22 |
23 |
--------------------------------------------------------------------------------
/27Aug2017/Objects/objects6.py:
--------------------------------------------------------------------------------
1 | class Dog():
2 | """A simple attempt to model a dog."""
3 | total = 0
4 | def __init__(a,name,age):
5 | print("Dog init")
6 | print("Name ",name)
7 | print("Age ", age)
8 | a.name = name
9 | a.age = age
10 | Dog.total = Dog.total+1
11 |
12 | def bark(b):
13 | print(b.name +" is barking")
14 |
15 | myDog = Dog("willie",6)
16 | yourDog = Dog("lucy",3)
17 |
18 | myDog.bark()
19 | yourDog.bark()
20 | print(Dog.total)
21 |
22 |
23 |
--------------------------------------------------------------------------------
/27Aug2017/Objects/objects7.py:
--------------------------------------------------------------------------------
1 | class Dog():
2 | """A simple attempt to model a dog."""
3 | total = 0
4 | def __init__(a,name,age):
5 | print("Dog init")
6 | print("Name ",name)
7 | print("Age ", age)
8 | a.name = name
9 | a.age = age
10 | Dog.total = Dog.total+1
11 |
12 | def bark(b):
13 | print(b.name +" is barking")
14 |
15 | myDog = Dog("willie",6)
16 | yourDog = Dog("lucy",3)
17 |
18 | myDog.bark()
19 | yourDog.bark()
20 | print(Dog.total)
21 |
22 |
23 |
--------------------------------------------------------------------------------
/27Aug2017/Objects/objects8.py:
--------------------------------------------------------------------------------
1 | class Car():
2 |
3 | def __init__(self,make,model,year):
4 | self.make = make
5 | self.model = model
6 | self.year = year
7 |
8 | def get_descriptive_name(self):
9 | long_name = str(self.year)+ ' '+self.make + ' ' + self.model
10 | return long_name
11 |
12 |
13 | c = Car('audi', 'a4', 2016)
14 | name = c.get_descriptive_name()
15 | print(name)
16 |
17 |
18 |
--------------------------------------------------------------------------------
/27Aug2017/Objects/objects9.py:
--------------------------------------------------------------------------------
1 | class Car():
2 |
3 | def __init__(self,make,model,year):
4 | self.make = make
5 | self.model = model
6 | self.year = year
7 | self.odometer_reading = 0
8 |
9 |
10 | def get_descriptive_name(self):
11 | long_name = str(self.year)+ ' '+self.make + ' ' + self.model
12 | return long_name
13 |
14 |
15 | c = Car('audi', 'a4', 2016)
16 | name = c.get_descriptive_name()
17 | print(name)
18 |
--------------------------------------------------------------------------------
/29Oct2017/29Oct2017/datascience_chap1/.idea/datascience_chap1.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/29Oct2017/29Oct2017/datascience_chap1/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/29Oct2017/29Oct2017/datascience_chap1/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/29Oct2017/29Oct2017/datascience_chap1/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 | 1509269691372
275 |
276 |
277 | 1509269691372
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
--------------------------------------------------------------------------------
/29Oct2017/29Oct2017/datascience_chap1/demo1.py:
--------------------------------------------------------------------------------
1 | interests = [
2 | (0, "Hadoop"), (0, "Big Data"), (0, "HBase"), (0, "Java"),
3 | (0, "Spark"), (0, "Storm"), (0, "Cassandra"),
4 | (1, "NoSQL"), (1, "MongoDB"), (1, "Cassandra"), (1, "HBase"),
5 | (1, "Postgres"), (2, "Python"), (2, "scikit-learn"), (2, "scipy"),
6 | (2, "numpy"), (2, "statsmodels"), (2, "pandas"), (3, "R"), (3, "Python"),
7 | (3, "statistics"), (3, "regression"), (3, "probability"),
8 | (4, "machine learning"), (4, "regression"), (4, "decision trees"),
9 | (4, "libsvm"), (5, "Python"), (5, "R"), (5, "Java"), (5, "C++"),
10 | (5, "Haskell"), (5, "programming languages"), (6, "statistics"),
11 | (6, "probability"), (6, "mathematics"), (6, "theory"),
12 | (7, "machine learning"), (7, "scikit-learn"), (7, "Mahout"),
13 | (7, "neural networks"), (8, "neural networks"), (8, "deep learning"),
14 | (8, "Big Data"), (8, "artificial intelligence"), (9, "Hadoop"),
15 | (9, "Java"), (9, "MapReduce"), (9, "Big Data")
16 | ]
17 |
18 |
19 | def data_scientists_who_like(target_interest):
20 | return [user_id
21 | for user_id, user_interest in interests
22 | if user_interest == target_interest]
23 |
24 |
25 | print(data_scientists_who_like("Java"))
--------------------------------------------------------------------------------
/29Oct2017/29Oct2017/datascience_chap1/demo2.py:
--------------------------------------------------------------------------------
1 | from collections import defaultdict
2 |
3 | interests = [
4 | (0, "Hadoop"), (0, "Big Data"), (0, "HBase"), (0, "Java"),
5 | (0, "Spark"), (0, "Storm"), (0, "Cassandra"),
6 | (1, "NoSQL"), (1, "MongoDB"), (1, "Cassandra"), (1, "HBase"),
7 | (1, "Postgres"), (2, "Python"), (2, "scikit-learn"), (2, "scipy"),
8 | (2, "numpy"), (2, "statsmodels"), (2, "pandas"), (3, "R"), (3, "Python"),
9 | (3, "statistics"), (3, "regression"), (3, "probability"),
10 | (4, "machine learning"), (4, "regression"), (4, "decision trees"),
11 | (4, "libsvm"), (5, "Python"), (5, "R"), (5, "Java"), (5, "C++"),
12 | (5, "Haskell"), (5, "programming languages"), (6, "statistics"),
13 | (6, "probability"), (6, "mathematics"), (6, "theory"),
14 | (7, "machine learning"), (7, "scikit-learn"), (7, "Mahout"),
15 | (7, "neural networks"), (8, "neural networks"), (8, "deep learning"),
16 | (8, "Big Data"), (8, "artificial intelligence"), (9, "Hadoop"),
17 | (9, "Java"), (9, "MapReduce"), (9, "Big Data")
18 | ]
19 |
20 | user_ids_by_interest = defaultdict(list)
21 | for user_id, interest in interests:
22 | user_ids_by_interest[interest].append(user_id)
23 |
24 | print(user_ids_by_interest)
25 |
26 | for item, val in user_ids_by_interest.items():
27 | print(item,val)
28 |
29 |
--------------------------------------------------------------------------------
/29Oct2017/29Oct2017/datascience_chap1/demo3.py:
--------------------------------------------------------------------------------
1 | from collections import defaultdict
2 |
3 | interests = [
4 | (0, "Hadoop"), (0, "Big Data"), (0, "HBase"), (0, "Java"),
5 | (0, "Spark"), (0, "Storm"), (0, "Cassandra"),
6 | (1, "NoSQL"), (1, "MongoDB"), (1, "Cassandra"), (1, "HBase"),
7 | (1, "Postgres"), (2, "Python"), (2, "scikit-learn"), (2, "scipy"),
8 | (2, "numpy"), (2, "statsmodels"), (2, "pandas"), (3, "R"), (3, "Python"),
9 | (3, "statistics"), (3, "regression"), (3, "probability"),
10 | (4, "machine learning"), (4, "regression"), (4, "decision trees"),
11 | (4, "libsvm"), (5, "Python"), (5, "R"), (5, "Java"), (5, "C++"),
12 | (5, "Haskell"), (5, "programming languages"), (6, "statistics"),
13 | (6, "probability"), (6, "mathematics"), (6, "theory"),
14 | (7, "machine learning"), (7, "scikit-learn"), (7, "Mahout"),
15 | (7, "neural networks"), (8, "neural networks"), (8, "deep learning"),
16 | (8, "Big Data"), (8, "artificial intelligence"), (9, "Hadoop"),
17 | (9, "Java"), (9, "MapReduce"), (9, "Big Data")
18 | ]
19 |
20 | user_ids_by_interest = defaultdict(list)
21 | for user_id, interest in interests:
22 | user_ids_by_interest[interest].append(user_id)
23 |
24 | print(user_ids_by_interest)
25 |
26 | for item, val in user_ids_by_interest.items():
27 | print(item,val)
28 |
29 | # keys are user_ids, values are lists of interests for that user_id
30 | interests_by_user_id = defaultdict(list)
31 |
32 | for user_id, interest in interests:
33 | interests_by_user_id[user_id].append(interest)
34 |
35 |
36 | for item, val in interests_by_user_id.items():
37 | print(item,val)
--------------------------------------------------------------------------------
/29Oct2017/29Oct2017/datascience_chap1/demo4.py:
--------------------------------------------------------------------------------
1 | from collections import defaultdict, Counter
2 | users = [
3 | { "id": 0, "name": "Hero" },
4 | { "id": 1, "name": "Dunn" },
5 | { "id": 2, "name": "Sue" },
6 | { "id": 3, "name": "Chi" },
7 | { "id": 4, "name": "Thor" },
8 | { "id": 5, "name": "Clive" },
9 | { "id": 6, "name": "Hicks" },
10 | { "id": 7, "name": "Devin" },
11 | { "id": 8, "name": "Kate" },
12 | { "id": 9, "name": "Klein" }
13 | ]
14 |
15 | interests = [
16 | (0, "Hadoop"), (0, "Big Data"), (0, "HBase"), (0, "Java"),
17 | (0, "Spark"), (0, "Storm"), (0, "Cassandra"),
18 | (1, "NoSQL"), (1, "MongoDB"), (1, "Cassandra"), (1, "HBase"),
19 | (1, "Postgres"), (2, "Python"), (2, "scikit-learn"), (2, "scipy"),
20 | (2, "numpy"), (2, "statsmodels"), (2, "pandas"), (3, "R"), (3, "Python"),
21 | (3, "statistics"), (3, "regression"), (3, "probability"),
22 | (4, "machine learning"), (4, "regression"), (4, "decision trees"),
23 | (4, "libsvm"), (5, "Python"), (5, "R"), (5, "Java"), (5, "C++"),
24 | (5, "Haskell"), (5, "programming languages"), (6, "statistics"),
25 | (6, "probability"), (6, "mathematics"), (6, "theory"),
26 | (7, "machine learning"), (7, "scikit-learn"), (7, "Mahout"),
27 | (7, "neural networks"), (8, "neural networks"), (8, "deep learning"),
28 | (8, "Big Data"), (8, "artificial intelligence"), (9, "Hadoop"),
29 | (9, "Java"), (9, "MapReduce"), (9, "Big Data")
30 | ]
31 |
32 | user_ids_by_interest = defaultdict(list)
33 | for user_id, interest in interests:
34 | user_ids_by_interest[interest].append(user_id)
35 |
36 | print(user_ids_by_interest)
37 |
38 | # keys are user_ids, values are lists of interests for that user_id
39 | interests_by_user_id = defaultdict(list)
40 |
41 | for user_id, interest in interests:
42 | interests_by_user_id[user_id].append(interest)
43 | print(interests_by_user_id)
44 |
45 |
46 | def most_common_interests_with(user):
47 | return Counter(interested_user_id
48 | for interest in interests_by_user_id[user["id"]]
49 | for interested_user_id in user_ids_by_interest[interest]
50 | if interested_user_id != user["id"])
51 |
52 | print(most_common_interests_with(users[0]))
53 |
--------------------------------------------------------------------------------
/29Oct2017/29Oct2017/datascience_chap1/demo5.py:
--------------------------------------------------------------------------------
1 | from collections import defaultdict, Counter
2 | users = [
3 | { "id": 0, "name": "Hero" },
4 | { "id": 1, "name": "Dunn" },
5 | { "id": 2, "name": "Sue" },
6 | { "id": 3, "name": "Chi" },
7 | { "id": 4, "name": "Thor" },
8 | { "id": 5, "name": "Clive" },
9 | { "id": 6, "name": "Hicks" },
10 | { "id": 7, "name": "Devin" },
11 | { "id": 8, "name": "Kate" },
12 | { "id": 9, "name": "Klein" }
13 | ]
14 |
15 | interests = [
16 | (0, "Hadoop"), (0, "Big Data"), (0, "HBase"), (0, "Java"),
17 | (0, "Spark"), (0, "Storm"), (0, "Cassandra"),
18 | (1, "NoSQL"), (1, "MongoDB"), (1, "Cassandra"), (1, "HBase"),
19 | (1, "Postgres"), (2, "Python"), (2, "scikit-learn"), (2, "scipy"),
20 | (2, "numpy"), (2, "statsmodels"), (2, "pandas"), (3, "R"), (3, "Python"),
21 | (3, "statistics"), (3, "regression"), (3, "probability"),
22 | (4, "machine learning"), (4, "regression"), (4, "decision trees"),
23 | (4, "libsvm"), (5, "Python"), (5, "R"), (5, "Java"), (5, "C++"),
24 | (5, "Haskell"), (5, "programming languages"), (6, "statistics"),
25 | (6, "probability"), (6, "mathematics"), (6, "theory"),
26 | (7, "machine learning"), (7, "scikit-learn"), (7, "Mahout"),
27 | (7, "neural networks"), (8, "neural networks"), (8, "deep learning"),
28 | (8, "Big Data"), (8, "artificial intelligence"), (9, "Hadoop"),
29 | (9, "Java"), (9, "MapReduce"), (9, "Big Data")
30 | ]
31 |
32 | user_ids_by_interest = defaultdict(list)
33 | for user_id, interest in interests:
34 | user_ids_by_interest[interest].append(user_id)
35 |
36 | print(user_ids_by_interest)
37 |
38 | # keys are user_ids, values are lists of interests for that user_id
39 | interests_by_user_id = defaultdict(list)
40 |
41 | for user_id, interest in interests:
42 | interests_by_user_id[user_id].append(interest)
43 | print(interests_by_user_id)
44 |
45 |
46 | def most_common_interests_with(user):
47 | return Counter(interested_user_id
48 | for interest in interests_by_user_id[user["id"]]
49 | for interested_user_id in user_ids_by_interest[interest]
50 | if interested_user_id != user["id"])
51 |
52 | print(most_common_interests_with(users[0]))
53 |
54 | def most_common_interests_with_names(user):
55 | common_interest = defaultdict(list)
56 | for interest in interests_by_user_id[user["id"]]:
57 | for other_interest_user_id in user_ids_by_interest[interest]:
58 | if user["id"] != other_interest_user_id:
59 | common_interest[other_interest_user_id].append(interest)
60 | return common_interest
61 |
62 |
63 |
64 |
65 | print(most_common_interests_with_names(users[0]))
66 |
--------------------------------------------------------------------------------
/29Oct2017/29Oct2017/datascience_chap1/demo6.py:
--------------------------------------------------------------------------------
1 | from collections import defaultdict
2 | salaries_and_tenures = [(83000, 8.7), (88000, 8.1),
3 | (48000, 0.7), (76000, 6),
4 | (69000, 6.5), (76000, 7.5),
5 | (60000, 2.5), (83000, 10),
6 | (48000, 1.9), (63000, 4.2),
7 | (65000, 4.2)
8 | ]
9 |
10 | salary_by_tenure = defaultdict(list)
11 | for salary, tenure in salaries_and_tenures:
12 | salary_by_tenure[tenure].append(salary)
13 |
14 | print(salary_by_tenure)
--------------------------------------------------------------------------------
/29Oct2017/29Oct2017/datascience_chap1/demo7.py:
--------------------------------------------------------------------------------
1 | from collections import defaultdict
2 | salaries_and_tenures = [(83000, 8.7), (88000, 8.1),
3 | (48000, 0.7), (76000, 6),
4 | (69000, 6.5), (76000, 7.5),
5 | (60000, 2.5), (83000, 10),
6 | (48000, 1.9), (63000, 4.2),
7 | (65000, 4.2)
8 | ]
9 |
10 | salary_by_tenure = defaultdict(list)
11 | for salary, tenure in salaries_and_tenures:
12 | salary_by_tenure[tenure].append(salary)
13 |
14 | print(salary_by_tenure)
15 |
16 | # keys are years, each value is average salary for that tenure
17 | average_salary_by_tenure = {
18 | tenure : sum(salaries) / len(salaries)
19 | for tenure, salaries in salary_by_tenure.items()
20 | }
21 |
22 | print(average_salary_by_tenure)
--------------------------------------------------------------------------------
/29Oct2017/29Oct2017/datascience_chap1/demo8.py:
--------------------------------------------------------------------------------
1 | from collections import defaultdict
2 | salaries_and_tenures = [(83000, 8.7), (88000, 8.1),
3 | (48000, 0.7), (76000, 6),
4 | (69000, 6.5), (76000, 7.5),
5 | (60000, 2.5), (83000, 10),
6 | (48000, 1.9), (63000, 4.2),
7 | (65000, 4.2)
8 | ]
9 |
10 | def tenure_bucket(tenure):
11 | if tenure < 2:
12 | return "less than two"
13 | elif tenure < 5:
14 | return "between two and five"
15 | else:
16 | return "more than five"
17 |
18 |
19 | salary_by_tenure_bucket = defaultdict(list)
20 | for salary, tenure in salaries_and_tenures:
21 | bucket = tenure_bucket(tenure)
22 | salary_by_tenure_bucket[bucket].append(salary)
23 |
24 | print(salary_by_tenure_bucket)
25 |
26 | # keys are tenure buckets, values are average salary for that bucket
27 | average_salary_by_bucket = {
28 | tenure_bucket : sum(salaries) / len(salaries)
29 | for tenure_bucket, salaries in salary_by_tenure_bucket.items()
30 | }
31 |
32 | print(average_salary_by_bucket)
--------------------------------------------------------------------------------
/29Oct2017/29Oct2017/demoObjects/.idea/demoObjects.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/29Oct2017/29Oct2017/demoObjects/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/29Oct2017/29Oct2017/demoObjects/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/29Oct2017/29Oct2017/demoObjects/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 | 1509275691937
95 |
96 |
97 | 1509275691937
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
--------------------------------------------------------------------------------
/29Oct2017/29Oct2017/demoObjects/obj1.py:
--------------------------------------------------------------------------------
1 | hmgjgjghjh
2 |
--------------------------------------------------------------------------------
/30July2017/DemoList/.idea/DemoList.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/30July2017/DemoList/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/30July2017/DemoList/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/30July2017/DemoList/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/30July2017/DemoList/List1.py:
--------------------------------------------------------------------------------
1 | bicycles = ['trek', 'cannondale',
2 | 'redline', 'specialized']
3 | print(bicycles)
4 | print(bicycles[0])
5 | singleBicycle = bicycles[2]
6 | print(singleBicycle.upper())
7 | print(bicycles)
8 | print(bicycles[-3])
--------------------------------------------------------------------------------
/30July2017/DemoList/List10.py:
--------------------------------------------------------------------------------
1 | cars = ['bmw', 'audi', 'toyota', 'subaru',"abc"]
2 | print(cars)
3 |
4 | count = len(cars)
5 | print(count)
6 | print(cars[-1])
7 | print(cars[-10])
--------------------------------------------------------------------------------
/30July2017/DemoList/List2.py:
--------------------------------------------------------------------------------
1 | motorcycles = ['honda', 'yamaha', 'suzuki']
2 | print(motorcycles)
3 |
4 | #motorcycles[0] = 'ducati'
5 | motorcycles.append('ducati')
6 | print(motorcycles)
7 |
8 | motorcycles.insert(1,"hero")
9 | print(motorcycles)
10 |
11 | #motorcycles[5] = "Hello world"
12 | motorcycles.insert(5,"Hello World")
13 | print(motorcycles)
14 |
15 | del motorcycles[1];
16 | print(motorcycles)
17 |
18 |
--------------------------------------------------------------------------------
/30July2017/DemoList/List3.py:
--------------------------------------------------------------------------------
1 | motorcycles = ['honda', 'yamaha', 'suzuki']
2 | removedMotorCycles = []
3 | print(motorcycles)
4 |
5 | a1 = motorcycles.pop()
6 | removedMotorCycles.append(a1)
7 | print(motorcycles)
8 | print(a1)
9 |
10 | a2 = motorcycles.pop()
11 | removedMotorCycles.append(a2)
12 | print(motorcycles)
13 | print(a2)
--------------------------------------------------------------------------------
/30July2017/DemoList/List4.py:
--------------------------------------------------------------------------------
1 | motorcycles = ['honda', 'yamaha', 'suzuki']
2 | removedMotorCycles = []
3 | print(motorcycles)
4 |
5 | removedMotorCycles.append(motorcycles.pop())
6 |
7 | print(motorcycles)
8 | print(removedMotorCycles)
9 |
10 | removedMotorCycles.append(motorcycles.pop())
11 | print(motorcycles)
12 | print(removedMotorCycles)
13 |
--------------------------------------------------------------------------------
/30July2017/DemoList/List5.py:
--------------------------------------------------------------------------------
1 | motorcycles = ['honda', 'yamaha', 'suzuki']
2 | removedMotorCycles = []
3 | print(motorcycles)
4 |
5 | a1 = motorcycles.remove("yamaha")
6 | print(motorcycles)
7 | print(a1)
--------------------------------------------------------------------------------
/30July2017/DemoList/List6.py:
--------------------------------------------------------------------------------
1 | cars = ['bmw', 'audi', 'toyota', 'subaru']
2 | print(cars)
3 | cars.sort()
4 | print(cars)
--------------------------------------------------------------------------------
/30July2017/DemoList/List7.py:
--------------------------------------------------------------------------------
1 | cars = ['bmw', 'audi', 'toyota', 'subaru']
2 | print(cars)
3 | cars.sort(reverse=True)
4 | print(cars)
--------------------------------------------------------------------------------
/30July2017/DemoList/List8.py:
--------------------------------------------------------------------------------
1 | cars = ['bmw', 'audi', 'toyota', 'subaru']
2 | print(cars)
3 | #sortedList = sorted(cars)
4 | sortedList = cars.sort()
5 | print(cars)
6 | print(sortedList)
7 |
--------------------------------------------------------------------------------
/30July2017/DemoList/List9.py:
--------------------------------------------------------------------------------
1 | cars = ['bmw', 'audi', 'toyota', 'subaru']
2 | twoCars = cars[0] + " " +cars[1]
3 | print(twoCars)
4 |
5 | print(cars)
6 | cars.reverse()
7 | print(cars)
--------------------------------------------------------------------------------
/30July2017/DemoListChap4/.idea/DemoListChap4.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/30July2017/DemoListChap4/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/30July2017/DemoListChap4/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/30July2017/DemoListChap4/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/30July2017/DemoListChap4/List1.py:
--------------------------------------------------------------------------------
1 | magicians = ['alice', 'david', 'carolina']
2 |
3 | for magician in magicians:
4 | print("Hello Mr. ",magician)
5 | print(magician)
6 | print("Hello ")
--------------------------------------------------------------------------------
/30July2017/DemoListChap4/List2.py:
--------------------------------------------------------------------------------
1 | names = ["Wajid","Ali","Qasim","Zeeshan"]
2 |
3 | for a in names:
4 | print("Hello world",a)
5 | print("New line testing")
6 |
7 | print("Working")
--------------------------------------------------------------------------------
/30July2017/DemoListChap4/List3.py:
--------------------------------------------------------------------------------
1 | for value in range(1,15):
2 | print(value)
3 |
4 | for value in range(1,10,2):
5 | print(value)
6 | print("---")
7 | for value in range(100,0,-5):
8 |
9 | print(value)
--------------------------------------------------------------------------------
/30July2017/DemoListChap4/List4.py:
--------------------------------------------------------------------------------
1 | names = ["Wajid","Ali","Qasim","Zeeshan"]
2 | for value in range(0,len(names)):
3 | print(value)
4 | print(names[value])
--------------------------------------------------------------------------------
/30July2017/DemoListChap4/List5.py:
--------------------------------------------------------------------------------
1 | names = ["Wajid","Ali","Qasim","Zeeshan"]
2 | for value in range(len(names)-1,-1,-1):
3 | print(value)
4 | print(names[value])
--------------------------------------------------------------------------------
/30July2017/DemoListChap4/List6.py:
--------------------------------------------------------------------------------
1 | for value in range(1,10):
2 | abc = 34
3 | print("Hello", value)
4 |
5 | print("New", value)
6 | print("New2", abc)
--------------------------------------------------------------------------------
/30July2017/DemoListChap4/List7.py:
--------------------------------------------------------------------------------
1 |
2 | mylist = range(1,10)
3 | print(mylist)
4 | mylist2 = list(range(1,5));
5 | print(mylist2)
6 |
7 | mylist3 = list(range(1,20,3));
8 | print(mylist3)
--------------------------------------------------------------------------------
/6Aug2017/DemoIfElse/.idea/DemoIfElse.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/6Aug2017/DemoIfElse/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/6Aug2017/DemoIfElse/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/6Aug2017/DemoIfElse/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/6Aug2017/DemoIfElse/IfElse1.py:
--------------------------------------------------------------------------------
1 | cars = ['audi', 'bmw', 'subaru', 'toyota']
2 | for car in cars:
3 | if car == 'bmw':
4 | print(car.upper())
5 | else:
6 | print(car.title())
--------------------------------------------------------------------------------
/6Aug2017/DemoIfElse/IfElse2.py:
--------------------------------------------------------------------------------
1 | marks = 95
2 |
3 | if marks > 80:
4 | print("A+")
5 | elif marks >70:
6 | print("A")
7 | elif marks >60:
8 | print("B")
9 | elif marks > 50:
10 | print("C")
11 | elif marks > 40:
12 | print("D")
13 | else:
14 | print("Failed")
15 |
16 |
--------------------------------------------------------------------------------
/6Aug2017/DemoIfElse/IfElse3.py:
--------------------------------------------------------------------------------
1 | marks = 95
2 |
3 | if marks > 40:
4 | print("D")
5 | elif marks > 50:
6 | print("C")
7 | elif marks > 60:
8 | print("B")
9 | elif marks >70:
10 | print("A")
11 | elif marks > 80:
12 | print("A+")
13 | else:
14 | print("Failed")
15 |
16 |
--------------------------------------------------------------------------------
/6Aug2017/DemoIfElse/IfElse4.py:
--------------------------------------------------------------------------------
1 | marks = 70
2 |
3 | if marks > 40 and marks < 50:
4 | print("D")
5 | elif marks > 50 and marks <60:
6 | print("C")
7 | elif marks > 60 and marks <70:
8 | print("B")
9 | elif marks >70 and marks < 80:
10 | print("A")
11 | elif marks > 80:
12 | print("A+")
13 | else:
14 | print("Failed")
15 |
16 |
--------------------------------------------------------------------------------
/6Aug2017/DemoIfElse/IfElse5.py:
--------------------------------------------------------------------------------
1 | marks = 39
2 |
3 | if marks >= 40 and marks < 50:
4 | print("D")
5 | elif marks >= 50 and marks <60:
6 | print("C")
7 | elif marks >= 60 and marks <70:
8 | print("B")
9 | elif marks >= 70 and marks < 80:
10 | print("A")
11 | elif marks >= 80:
12 | print("A+")
13 | else:
14 | print("Failed")
15 |
16 |
--------------------------------------------------------------------------------
/6Aug2017/DemoIfElse/InOperator.py:
--------------------------------------------------------------------------------
1 | requested_toppings = ['mushrooms', 'onions', 'pineapple']
2 |
3 | print('moshrooms' in requested_toppings)
4 |
5 | if 'mushrooms' in requested_toppings:
6 | print("Ok Sir")
7 | else :
8 | print("Sorry, not available Sir ")
9 |
--------------------------------------------------------------------------------
/6Aug2017/DemoList/.idea/DemoList.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/6Aug2017/DemoList/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/6Aug2017/DemoList/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/6Aug2017/DemoList/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/6Aug2017/DemoList/List1.py:
--------------------------------------------------------------------------------
1 | squares = []
2 |
3 | for value in range(1,11):
4 | square = value**2
5 | square = square+2
6 | squares.append(square)
7 |
8 |
9 | print(squares)
10 |
--------------------------------------------------------------------------------
/6Aug2017/DemoList/List10.py:
--------------------------------------------------------------------------------
1 | players = ['charles', 'martina', 'michael',
2 | 'florence', 'eli',"asdf",
3 | "asdfa","asdfadf","astest"]
4 | fewPlayers = players[:]
5 | print(fewPlayers)
6 | print(players)
--------------------------------------------------------------------------------
/6Aug2017/DemoList/List11.py:
--------------------------------------------------------------------------------
1 | players = ['charles', 'martina', 'michael',
2 | 'florence', 'eli',"1",
3 | "2","3","4"]
4 | fewPlayers = players[1:6:2]
5 | print(fewPlayers)
6 | print(players)
--------------------------------------------------------------------------------
/6Aug2017/DemoList/List12.py:
--------------------------------------------------------------------------------
1 | players = ['charles', 'martina', 'michael',
2 | 'florence', 'eli',"1",
3 | "2","3","4"]
4 | fewPlayers = players[::2]
5 | print(fewPlayers)
6 | print(players)
--------------------------------------------------------------------------------
/6Aug2017/DemoList/List13.py:
--------------------------------------------------------------------------------
1 | players = ['charles', 'martina', 'michael',
2 | 'florence', 'eli',"1",
3 | "2","3","4"]
4 | print(players)
5 | for p in players[::2]:
6 | print(p.title())
7 |
8 |
--------------------------------------------------------------------------------
/6Aug2017/DemoList/List14.py:
--------------------------------------------------------------------------------
1 | players = ['charles', 'martina', 'michael',
2 | 'florence', 'eli',"1",
3 | "2","3","4"]
4 | print(players)
5 | print(players[-3])
6 | fewPlayers = players[-3:]
7 | print(fewPlayers)
8 |
9 |
--------------------------------------------------------------------------------
/6Aug2017/DemoList/List15.py:
--------------------------------------------------------------------------------
1 | players = ['charles', 'martina', 'michael',
2 | 'florence', 'eli',"1",
3 | "2","3","4"]
4 | print(players)
5 | print(players[-3])
6 | fewPlayers = players[-5:-3]
7 | print(fewPlayers)
8 |
9 |
--------------------------------------------------------------------------------
/6Aug2017/DemoList/List16.py:
--------------------------------------------------------------------------------
1 | players = ['charles', 'martina', 'michael',
2 | 'florence', 'eli',"1",
3 | "2","3","4"]
4 | print(players)
5 | print(players[-3])
6 | fewPlayers = players[-3:-7:-1]
7 | print(fewPlayers)
8 |
9 |
--------------------------------------------------------------------------------
/6Aug2017/DemoList/List17.py:
--------------------------------------------------------------------------------
1 | players = ['charles', 'martina', 'michael',
2 | 'florence', 'eli',"1",
3 | "2","3","4"]
4 | print(players)
5 | print(players[-3])
6 | fewPlayers = players[::-1]
7 | print(fewPlayers)
8 |
9 |
--------------------------------------------------------------------------------
/6Aug2017/DemoList/List18.py:
--------------------------------------------------------------------------------
1 | my_foods = ['pizza', 'falafel', 'carrot cake']
2 | friend_foods = my_foods[:]
3 | my_foods.append('cannoli')
4 | friend_foods.append('ice cream')
5 | print("My favorite foods are:")
6 | print(my_foods)
7 | print(friend_foods)
--------------------------------------------------------------------------------
/6Aug2017/DemoList/List2.py:
--------------------------------------------------------------------------------
1 | squares = []
2 |
3 | for value in range(1,11):
4 | squares.append(value**2)
5 |
6 |
7 | print(squares)
8 |
--------------------------------------------------------------------------------
/6Aug2017/DemoList/List3.py:
--------------------------------------------------------------------------------
1 | squares = []
2 |
3 | for value in range(1,11):
4 | squares.append(value**2)
5 |
6 |
7 | print(squares)
8 |
9 | minVal = min(squares)
10 | maxVal = max(squares)
11 | sumVal = sum(squares)
12 | countVal = len(squares)
13 |
14 | print("Min",minVal)
15 | print("Max",maxVal)
16 | print("Sum",sumVal)
17 | print("Count",countVal)
18 | print("Average",sumVal/countVal)
19 |
20 |
21 |
--------------------------------------------------------------------------------
/6Aug2017/DemoList/List4.py:
--------------------------------------------------------------------------------
1 | values = [val for val in range(1,11)]
2 | values2 = [val for val in range(1,11,2)]
3 | squares = [value**2+2 for value in range(1,11)]
4 | print(squares)
5 |
--------------------------------------------------------------------------------
/6Aug2017/DemoList/List5.py:
--------------------------------------------------------------------------------
1 | print([val for val in range(1,11)])
--------------------------------------------------------------------------------
/6Aug2017/DemoList/List6.py:
--------------------------------------------------------------------------------
1 | players = ['charles', 'martina', 'michael', 'florence', 'eli']
2 | fewPlayers = players[1:3]
3 | print(fewPlayers)
4 | fewPlayers[0] = "Hello"
5 | print(fewPlayers)
6 | print(players)
--------------------------------------------------------------------------------
/6Aug2017/DemoList/List7.py:
--------------------------------------------------------------------------------
1 | players = ['charles', 'martina', 'michael',
2 | 'florence', 'eli',"asdf",
3 | "asdfa","asdfadf","astest"]
4 | fewPlayers = players[4:7]
5 | print(fewPlayers)
6 | print(players)
--------------------------------------------------------------------------------
/6Aug2017/DemoList/List8.py:
--------------------------------------------------------------------------------
1 | players = ['charles', 'martina', 'michael',
2 | 'florence', 'eli',"asdf",
3 | "asdfa","asdfadf","astest"]
4 | fewPlayers = players[:4]
5 | print(fewPlayers)
6 | print(players)
--------------------------------------------------------------------------------
/6Aug2017/DemoList/List9.py:
--------------------------------------------------------------------------------
1 | players = ['charles', 'martina', 'michael',
2 | 'florence', 'eli',"asdf",
3 | "asdfa","asdfadf","astest"]
4 | fewPlayers = players[4:]
5 | print(fewPlayers)
6 | print(players)
--------------------------------------------------------------------------------
/6Aug2017/DemoTuple/.idea/DemoTuple.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/6Aug2017/DemoTuple/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/6Aug2017/DemoTuple/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/6Aug2017/DemoTuple/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/6Aug2017/DemoTuple/tuple1.py:
--------------------------------------------------------------------------------
1 | dimensions = (200, 50)
2 | print(dimensions)
3 | print(dimensions[0])
4 | print(dimensions[1])
5 |
6 |
7 |
--------------------------------------------------------------------------------
/6Aug2017/DemoTuple/tuple2.py:
--------------------------------------------------------------------------------
1 | dimensions = (200, 50)
2 | print(dimensions)
3 | #dimensions.append(34)
4 | print(dimensions)
5 |
6 |
7 |
--------------------------------------------------------------------------------
/6Aug2017/DemoTuple/tuple3.py:
--------------------------------------------------------------------------------
1 | dimensions = (200, 50)
2 | print(dimensions)
3 | dimensions[1] = 45
4 | print(dimensions)
5 |
6 |
7 |
--------------------------------------------------------------------------------
/6Aug2017/DemoTuple/tuple4.py:
--------------------------------------------------------------------------------
1 | dimensions = tuple(range(1,11))
2 | print(dimensions)
3 | for d in dimensions:
4 | print(d)
5 |
6 |
7 |
--------------------------------------------------------------------------------
/6Aug2017/DemoTuple/tuple5.py:
--------------------------------------------------------------------------------
1 | dimensions = (200,500)
2 | print(dimensions)
3 | dimensions = (300,500)
4 | print(dimensions)
5 |
6 |
--------------------------------------------------------------------------------
/6Aug2017/DemoTuple/tuple6.py:
--------------------------------------------------------------------------------
1 | dimensions = tuple(val**2 for val in range(1,11))
2 | print(dimensions)
3 |
4 |
--------------------------------------------------------------------------------
/8Oct2017/datascience_chap2/.idea/datascience_chap2.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/8Oct2017/datascience_chap2/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/8Oct2017/datascience_chap2/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/8Oct2017/datascience_chap2/demo1.py:
--------------------------------------------------------------------------------
1 | document = "That the quick brown fox jumps over the lazy dog"
2 |
3 | word_counts = {}
4 | for word in document.split():
5 | if word in word_counts:
6 | word_counts[word] += 1
7 | else:
8 | word_counts[word] = 1
9 |
10 | print(word_counts)
--------------------------------------------------------------------------------
/8Oct2017/datascience_chap2/demo10.py:
--------------------------------------------------------------------------------
1 | document = "That the quick brown fox jumps quick over fox the lazy dog fox Jumps"
2 |
3 | word_counts = {}
4 | for word in document.split():
5 | if word in word_counts:
6 | word_counts[word] += 1
7 | else:
8 | word_counts[word] = 1
9 |
10 | print(word_counts)
11 | print(word_counts.items())
12 |
13 | wc = sorted(word_counts.items())
14 | print(wc)
--------------------------------------------------------------------------------
/8Oct2017/datascience_chap2/demo11.py:
--------------------------------------------------------------------------------
1 | document = "That the quick brown fox jumps quick over fox the lazy dog fox Jumps"
2 |
3 | word_counts = {}
4 | for word in document.split():
5 | if word in word_counts:
6 | word_counts[word] += 1
7 | else:
8 | word_counts[word] = 1
9 |
10 | print(word_counts)
11 | print(word_counts.items())
12 |
13 | wc = sorted(word_counts.items(),key=lambda i: i[1],reverse=True)
14 | print(wc)
--------------------------------------------------------------------------------
/8Oct2017/datascience_chap2/demo12.py:
--------------------------------------------------------------------------------
1 | even_numbers = [x for x in range(5) if x%2 == 0]
2 | print(even_numbers)
3 |
4 | zeroes = [0 for _ in even_numbers]
5 | print(zeroes)
6 |
7 | ab = [4,6,8,25,14]
8 | def abc (a):
9 | print(a)
10 |
11 | even_numbers1 = [x for x in range(15) if abc(x)]
12 | print(even_numbers1)
13 |
14 |
--------------------------------------------------------------------------------
/8Oct2017/datascience_chap2/demo13.py:
--------------------------------------------------------------------------------
1 | x = range(10)
2 | y = list(x)
3 | print(x)
4 | print(y)
5 | for z in x:
6 | print(z)
7 |
--------------------------------------------------------------------------------
/8Oct2017/datascience_chap2/demo14.py:
--------------------------------------------------------------------------------
1 | def myFunction(count):
2 | print("count",count)
3 | for x in range(count):
4 | yield x
5 |
6 | myval = myFunction(10)
7 | print(myval)
8 | print(next(myval))
9 | print(next(myval))
10 | print(next(myval))
11 |
12 | #for z in myval:
13 | # print(z)
--------------------------------------------------------------------------------
/8Oct2017/datascience_chap2/demo15.py:
--------------------------------------------------------------------------------
1 | def myFunction(count):
2 | print("count",count)
3 | for x in range(count):
4 | yield x
5 |
6 | myval = myFunction(10)
7 | print(myval)
8 |
9 |
10 | for z in myval:
11 | print(z)
--------------------------------------------------------------------------------
/8Oct2017/datascience_chap2/demo16.py:
--------------------------------------------------------------------------------
1 | import random
2 |
3 | a = random.choice(range(10))
4 | print(a)
5 |
6 |
7 | four_with_replacement = [
8 | x
9 | for x in range(4)]
10 |
11 | print(four_with_replacement)
12 |
13 |
14 | four_with_replacement1 = [
15 | random.choice(range(10))
16 | for _ in range(4)]
17 |
18 | print(four_with_replacement1)
--------------------------------------------------------------------------------
/8Oct2017/datascience_chap2/demo17.py:
--------------------------------------------------------------------------------
1 | import re
2 |
3 | myVal = "Hello World!"
4 | a = re.search("[a-z]", myVal)
5 | print(a.group())
6 |
--------------------------------------------------------------------------------
/8Oct2017/datascience_chap2/demo2.py:
--------------------------------------------------------------------------------
1 | from collections import defaultdict
2 | document = "That the quick brown fox jumps over the lazy dog"
3 |
4 | word_counts = defaultdict(int)
5 | for word in document.split():
6 | word_counts[word] += 1
7 |
8 | print(word_counts)
--------------------------------------------------------------------------------
/8Oct2017/datascience_chap2/demo3.py:
--------------------------------------------------------------------------------
1 | from collections import Counter
2 | document = "That the quick brown fox jumps quick over fox the lazy dog fox"
3 |
4 | c = Counter(document.split())
5 | print(c)
6 |
7 | if "a":
8 | print("Hello")
9 | else:
10 | print("else")
--------------------------------------------------------------------------------
/8Oct2017/datascience_chap2/demo4.py:
--------------------------------------------------------------------------------
1 | myList = [True, 1, { 3 },"a"]
2 |
3 | result = all(myList)
4 |
5 | print(result)
--------------------------------------------------------------------------------
/8Oct2017/datascience_chap2/demo5.py:
--------------------------------------------------------------------------------
1 | myList = [True, 0, { 3 },""]
2 |
3 | result = any(myList)
4 |
5 | print(result)
--------------------------------------------------------------------------------
/8Oct2017/datascience_chap2/demo6.py:
--------------------------------------------------------------------------------
1 | x = [4,1,2,3]
2 | #y = sorted(x) # is [1,2,3,4], x is unchanged
3 | x.sort()
4 | print(x)
5 | #print(y)
--------------------------------------------------------------------------------
/8Oct2017/datascience_chap2/demo7.py:
--------------------------------------------------------------------------------
1 | x = [-4,1,-2,3]
2 | y = sorted(x,key=abs)
3 |
4 | print(x)
5 | print(y)
--------------------------------------------------------------------------------
/8Oct2017/datascience_chap2/demo8.py:
--------------------------------------------------------------------------------
1 |
2 | a = lambda b:b*2 +4*b
3 |
4 | print(a)
5 | print(a(2))
6 |
--------------------------------------------------------------------------------
/8Oct2017/datascience_chap2/demo9.py:
--------------------------------------------------------------------------------
1 | x = [-4,1,-2,3]
2 |
3 | #a = lambda (a)
4 |
5 | y = sorted(x,key=lambda c:c*2)
6 | print(x)
7 | print(y)
8 |
9 |
10 | d = lambda c:c*2
11 | print(d(-4))
12 | print(d(1))
13 | print(d(-2))
14 | print(d(3))
15 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # python-code
2 | Python Code for AI class
3 |
--------------------------------------------------------------------------------