Skip to content

Commit 0ea3b4c

Browse files
committed
Update
1 parent f23709f commit 0ea3b4c

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

assignments.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Note: all Assignments are due at the beginning of class unless noted otherwise
1414
* [logs.zip]({{ site.baseurl }}/data/hw/logs.zip)
1515
* [Lab #3: Python]({{ site.baseurl }}/data/hw/lab3-python.py) (Due: Monday, 2/11/19)
1616
* [Lab #4: MapReduce]({{ site.baseurl }}/data/hw/MapReduce-hw.pdf) (Due: Wednesday, 2/20/19)
17+
* [lab4_help.py]({{ site.baseurl }}/data/hw/lab4_help.py)
1718
* [customers.zip]({{ site.baseurl }}/data/hw/customers.zip)
1819
* [Lab #5: MySQL]({{ site.baseurl }}/data/hw/MySQL.pdf) (Due: Wednesday, 3/06/19)
1920
* [Lab #6: Sqoop, Impala, and Hive]({{ site.baseurl }}/data/hw/sqoop.pdf) (Due: Wednesday, 3/20/19)

data/hw/lab4_help.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Sample Code for Lab 4
2+
3+
# Sample Code to Remove Punctuation
4+
5+
import string
6+
7+
# the string module includes punctuation characters
8+
print("punctuation characters:", string.punctuation)
9+
10+
# create a translation table, which says to delete all characters specified in
11+
# the third argument (i.e., to delete all punctuation)
12+
t = str.maketrans('', '', string.punctuation)
13+
14+
# example string
15+
s = "Look! Hey!?"
16+
17+
# call the translate function which translates string based on the translation table
18+
# in this case, all punctuation is removed
19+
new_s = s.translate(t)
20+
21+
print(s)
22+
print(new_s)
23+
24+
25+
# Sample code to work with a set (a collection of unique values)
26+
27+
# If you have a list, you can remove duplicate values by converting to a set
28+
l = ['a','b','c','a'] # create a list containing 'a','b','c', and 'a'
29+
s = set(l) # convert from a list to a set, which will contain only 'a','b',and 'c'
30+
print(s)
31+
print(','.join(s)) # print a comma-separated string of values
32+
33+
# You can keep a set of unique values as you go, by starting with an empty set
34+
s = set() # start with an empty set
35+
s.add('a') # add an 'a'
36+
s.add('b') # add a 'b'
37+
s.add('a') # 'a' is not added, since it already exists in the set
38+
print(s) # the set contains only 'a','b'
39+

0 commit comments

Comments
 (0)