Skip to content

Commit ed970c3

Browse files
author
David Kan
committed
Adding newly created files
1 parent e1b0324 commit ed970c3

7 files changed

Lines changed: 192 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env python
2+
# make a row that is goal inches long
3+
# 1: bricks and 5" bricks
4+
5+
# def make_bricks(num_small, num_big, goal):
6+
# if num_small * 1 + num_big * 5 < goal:
7+
# return False
8+
# return True
9+
#
10+
# assert make_bricks(3, 1, 8) is True
11+
# assert make_bricks(3, 1, 9) is False
12+
# assert make_bricks(3, 2, 10) is True
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
3+
infile = "students.txt"
4+
5+
all_langs = []
6+
with open(infile) as students:
7+
students.readline()
8+
for line in students:
9+
line = line.strip()
10+
langs = line.split(":")[1].split(",")
11+
if langs[0].strip()[0].isupper():
12+
langs = langs[1:]
13+
all_langs.extend(langs)
14+
print(langs)
15+
16+
all_langs = []
17+
for lang in all_langs:
18+
if lang.strip():
19+
new_langs.append(lang.strip())
20+
21+
all_langs = set(all_langs)
22+
print(all_langs)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# choices = ['pizza', 'pasta', 'salad', 'nachos']
2+
#
3+
# name = 'nachos'
4+
# for index, item in enumerate(choices):
5+
# if name in item:
6+
# print(index, item)
7+
#
8+
# find a dict call that can do this
9+
10+
words = "I wish I may I wish I might".split()
11+
12+
trigrams = {}
13+
for i in range(len(words)-2):
14+
pair = tuple(words[i:i+2])
15+
follower = words[i+2]
16+
print(pair, follower)
17+
if pair in trigrams:
18+
trigrams[pair].append(follower)
19+
else:
20+
trigrams[pair] = [follower]
21+
22+
print(trigrams)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Name: Languages
2+
Adams, Eric V: python, java, perl
3+
Anderson, Katherine Marguerite: Kate
4+
Baughman, Eowyn C: fortran, java, matlab, bash
5+
Beausoleil, Larry: python, powershell
6+
Briggs, Matthew D: c#, javascript, python, typescript
7+
Chao, Po-Sung: c++, java
8+
Chudasma, Amitkumar: Amit shell, python
9+
Dehghani, Ali:
10+
Egan, Kathryn: python, java
11+
Eng, Zandra: new
12+
Estrada, Marlon M: java, python, ruby
13+
Heinemann, Morgan: c++, python
14+
Kan, David K: java, c#, python
15+
Kuchan, Daniel W: Dan c++, matlab,
16+
Maeda, Matthew Sachio: Matt, c, perl, java, erlang, python
17+
Matenda, Alinafe: Nafe, java, perl, c#, c++, python
18+
Nagata, Brian: bash, python
19+
Navitsky, John:bash, python, ansible
20+
Olsby, Jacob: Jake, c#, powershell, python, sql
21+
Peterson, Scott B: python, r, visualbasic
22+
Shibata, Hiroyuki: php, mysql, python
23+
Takata, James: Jim, rex, db
24+
Takechi, Hiroyuki: Hiro, r
25+
Thadigol Reddappa, Srikanth: Sri, perl, python
26+
Thomas, Guillaume R: Tom, shell, python, vb
27+
Uvarov, Evgeny S: Gene, python
28+
Warn, Brian: fortran, perl, sql, python
29+
Wojciechowski, Daniel: Dan, c, c++, lisp
30+
Yaramati, Rajaramesh V: Ramesh, bash, python, sql
31+
Yen, Tian Chuan: java, python
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env python
2+
3+
from sys import argv
4+
5+
script, first, second, third = argv
6+
7+
print("The script is called:", script)
8+
print("Your first variable is ", first)
9+
print("Your second variable is:", second)
10+
print("Your third variable is:", third)
11+

‎students/davidkan/session05/input.csv‎

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/usr/bin/env python
2+
# Description: Demo on progressbar2 3.34.3 ref: https://pypi.python.org/pypi/progressbar2
3+
# Last modified on 10/29/2017 by David Kan
4+
5+
6+
from progressbar import ProgressBar, UnknownLength
7+
import csv
8+
import time
9+
10+
11+
def wrapping_an_iterable(bar):
12+
"""
13+
Function shows an example of wrapping an iterable
14+
Progress example: 100% (1000 of 1000) |#####################| Elapsed Time: 0:00:10 Time: 0:00:10
15+
:param bar: instance of ProgressBar
16+
:return: none
17+
"""
18+
for i in bar(range(1000)):
19+
time.sleep(0.01)
20+
21+
def context_wrapper():
22+
"""
23+
Function shows an example of a context wrapper
24+
Progress example: 100% (1000 of 1000) |#####################| Elapsed Time: 0:00:10 Time: 0:00:10
25+
:return: none
26+
"""
27+
with ProgressBar(max_value=1000) as bar:
28+
for i in range(1000):
29+
time.sleep(0.01)
30+
bar.update(i)
31+
32+
def progressbars_unknown_length():
33+
"""
34+
Function shows an example of how to use progressbar on an unknown length
35+
Progress example: | 995 Elapsed Time: 0:00:10
36+
:return: none
37+
"""
38+
bar = ProgressBar(max_value=UnknownLength)
39+
for i in range(1000):
40+
time.sleep(0.01)
41+
bar.update(i)
42+
43+
def read_csv_file(bar):
44+
"""
45+
Function reads in a csv file using the DictReader (class csv.DictReader)
46+
Create an object which operates like a regular reader but maps the information
47+
read into a dict whose keys are given by the optional fieldnames parameter
48+
ref: https://docs.python.org/2/library/csv.html#csv.DictReader
49+
:return: none
50+
"""
51+
with open('input.csv', newline='') as f:
52+
reader = csv.DictReader(f)
53+
header = next(reader)
54+
csv_to_dict(reader, header, bar)
55+
56+
def csv_to_dict(reader, header, bar):
57+
"""
58+
Function takes the csv file column name and value and adds it to a dict object. The progressbar in
59+
this function is an example of an unknown length of the reader object (<class 'csv.DictReader'>)
60+
:param reader: contains the values in each column
61+
:param header: contains the column names
62+
:param bar: instance of ProgressBar
63+
:return: none
64+
"""
65+
column_name = {}
66+
for name in header:
67+
column_name.setdefault(name, [])
68+
69+
for row in bar(reader):
70+
column_name['cdatetime'].append(row.get('cdatetime', None))
71+
column_name['address'].append(row.get('address', None))
72+
column_name['district'].append(row.get('district', None))
73+
column_name['beat'].append(row.get('beat', None))
74+
column_name['grid'].append(row.get('grid', None))
75+
column_name['crimedescr'].append(row.get('crimedescr', None))
76+
column_name['ucr_ncic_code'].append(row.get('ucr_ncic_code', None))
77+
column_name['latitude'].append(row.get('latitude', None))
78+
column_name['longitude'].append(row.get('longitude', None))
79+
time.sleep(0.01)
80+
81+
82+
if __name__ == "__main__":
83+
84+
# Create instance of ProgressBar
85+
bar = ProgressBar()
86+
87+
# Demo the main three commonly used progressbars
88+
wrapping_an_iterable(bar)
89+
# context_wrapper()
90+
# progressbars_unknown_length()
91+
92+
# Demo of progressbar for unknown length
93+
# read_csv_file(bar)

0 commit comments

Comments
 (0)