Skip to content

Commit 2b63143

Browse files
committed
Fixed lint errors in Files lecture
1 parent 5b2ab07 commit 2b63143

3 files changed

Lines changed: 144 additions & 76 deletions

File tree

data/baseball.csv

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
id,player,year,stint,team,lg,g,ab,r,h,X2b,X3b,hr,rbi,sb,cs,bb,so,ibb,hbp,sh,sf,gidp
2+
88641,womacto01,2006,2,CHN,NL,19,50,6,14,1,0,1,2.0,1.0,1.0,4,4.0,0.0,0.0,3.0,0.0,0.0
3+
88643,schilcu01,2006,1,BOS,AL,31,2,0,1,0,0,0,0.0,0.0,0.0,0,1.0,0.0,0.0,0.0,0.0,0.0
4+
88645,myersmi01,2006,1,NYA,AL,62,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
5+
88649,helliri01,2006,1,MIL,NL,20,3,0,0,0,0,0,0.0,0.0,0.0,0,2.0,0.0,0.0,0.0,0.0,0.0
6+
88650,johnsra05,2006,1,NYA,AL,33,6,0,1,0,0,0,0.0,0.0,0.0,0,4.0,0.0,0.0,0.0,0.0,0.0
7+
88652,finlest01,2006,1,SFN,NL,139,426,66,105,21,12,6,40.0,7.0,0.0,46,55.0,2.0,2.0,3.0,4.0,6.0
8+
88653,gonzalu01,2006,1,ARI,NL,153,586,93,159,52,2,15,73.0,0.0,1.0,69,58.0,10.0,7.0,0.0,6.0,14.0
9+
88662,seleaa01,2006,1,LAN,NL,28,26,2,5,1,0,0,0.0,0.0,0.0,1,7.0,0.0,0.0,6.0,0.0,1.0
10+
89177,francju01,2007,2,ATL,NL,15,40,1,10,3,0,0,8.0,0.0,0.0,4,10.0,1.0,0.0,0.0,1.0,1.0
11+
89178,francju01,2007,1,NYN,NL,40,50,7,10,0,0,1,8.0,2.0,1.0,10,13.0,0.0,0.0,0.0,1.0,1.0
12+
89330,zaungr01,2007,1,TOR,AL,110,331,43,80,24,1,10,52.0,0.0,0.0,51,55.0,8.0,2.0,1.0,6.0,9.0
13+
89333,witasja01,2007,1,TBA,AL,3,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
14+
89334,williwo02,2007,1,HOU,NL,33,59,3,6,0,0,1,2.0,0.0,0.0,0,25.0,0.0,0.0,5.0,0.0,1.0
15+
89335,wickmbo01,2007,2,ARI,NL,8,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
16+
89336,wickmbo01,2007,1,ATL,NL,47,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
17+
89337,whitero02,2007,1,MIN,AL,38,109,8,19,4,0,4,20.0,0.0,0.0,6,19.0,0.0,3.0,0.0,1.0,2.0
18+
89338,whiteri01,2007,1,HOU,NL,20,1,0,0,0,0,0,0.0,0.0,0.0,0,1.0,0.0,0.0,0.0,0.0,0.0
19+
89339,wellsda01,2007,2,LAN,NL,7,15,2,4,1,0,0,1.0,0.0,0.0,0,6.0,0.0,0.0,0.0,0.0,0.0
20+
89340,wellsda01,2007,1,SDN,NL,22,38,1,4,0,0,0,0.0,0.0,0.0,0,12.0,0.0,0.0,4.0,0.0,0.0
21+
89341,weathda01,2007,1,CIN,NL,67,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
22+
89343,walketo04,2007,1,OAK,AL,18,48,5,13,1,0,0,4.0,0.0,0.0,2,4.0,0.0,0.0,0.0,2.0,2.0
23+
89345,wakefti01,2007,1,BOS,AL,1,2,0,0,0,0,0,0.0,0.0,0.0,0,2.0,0.0,0.0,0.0,0.0,0.0
24+
89347,vizquom01,2007,1,SFN,NL,145,513,54,126,18,3,4,51.0,14.0,6.0,44,48.0,6.0,1.0,14.0,3.0,14.0
25+
89348,villoro01,2007,1,NYA,AL,6,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
26+
89352,valenjo03,2007,1,NYN,NL,51,166,18,40,11,1,3,18.0,2.0,1.0,15,28.0,4.0,0.0,1.0,1.0,5.0
27+
89354,trachst01,2007,2,CHN,NL,4,7,0,1,0,0,0,0.0,0.0,0.0,0,1.0,0.0,0.0,0.0,0.0,0.0
28+
89355,trachst01,2007,1,BAL,AL,3,5,0,0,0,0,0,0.0,0.0,0.0,0,3.0,0.0,0.0,0.0,0.0,0.0
29+
89359,timlimi01,2007,1,BOS,AL,4,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
30+
89360,thomeji01,2007,1,CHA,AL,130,432,79,119,19,0,35,96.0,0.0,1.0,95,134.0,11.0,6.0,0.0,3.0,10.0
31+
89361,thomafr04,2007,1,TOR,AL,155,531,63,147,30,0,26,95.0,0.0,0.0,81,94.0,3.0,7.0,0.0,5.0,14.0
32+
89363,tavarju01,2007,1,BOS,AL,2,4,0,1,0,0,0,0.0,0.0,0.0,1,3.0,0.0,0.0,0.0,0.0,0.0
33+
89365,sweenma01,2007,2,LAN,NL,30,33,2,9,1,0,0,3.0,0.0,0.0,1,11.0,0.0,0.0,0.0,0.0,0.0
34+
89366,sweenma01,2007,1,SFN,NL,76,90,18,23,8,0,2,10.0,2.0,0.0,13,18.0,0.0,3.0,1.0,0.0,0.0
35+
89367,suppaje01,2007,1,MIL,NL,33,61,4,8,0,0,0,2.0,0.0,0.0,3,16.0,0.0,0.0,11.0,0.0,2.0
36+
89368,stinnke01,2007,1,SLN,NL,26,82,7,13,3,0,1,5.0,0.0,0.0,5,22.0,2.0,0.0,0.0,0.0,2.0
37+
89370,stantmi02,2007,1,CIN,NL,67,2,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
38+
89371,stairma01,2007,1,TOR,AL,125,357,58,103,28,1,21,64.0,2.0,1.0,44,66.0,5.0,2.0,0.0,2.0,7.0
39+
89372,sprinru01,2007,1,SLN,NL,72,1,0,0,0,0,0,0.0,0.0,0.0,0,1.0,0.0,0.0,0.0,0.0,0.0
40+
89374,sosasa01,2007,1,TEX,AL,114,412,53,104,24,1,21,92.0,0.0,0.0,34,112.0,3.0,3.0,0.0,5.0,11.0
41+
89375,smoltjo01,2007,1,ATL,NL,30,54,1,5,1,0,0,2.0,0.0,0.0,1,19.0,0.0,0.0,13.0,0.0,0.0
42+
89378,sheffga01,2007,1,DET,AL,133,494,107,131,20,1,25,75.0,22.0,5.0,84,71.0,2.0,9.0,0.0,6.0,10.0
43+
89381,seleaa01,2007,1,NYN,NL,31,4,0,0,0,0,0,0.0,0.0,0.0,1,1.0,0.0,0.0,1.0,0.0,0.0
44+
89382,seaneru01,2007,1,LAN,NL,68,1,0,0,0,0,0,0.0,0.0,0.0,0,1.0,0.0,0.0,0.0,0.0,0.0
45+
89383,schmija01,2007,1,LAN,NL,6,7,1,1,0,0,1,1.0,0.0,0.0,0,4.0,0.0,0.0,1.0,0.0,0.0
46+
89384,schilcu01,2007,1,BOS,AL,1,2,0,1,0,0,0,0.0,0.0,0.0,0,1.0,0.0,0.0,0.0,0.0,0.0
47+
89385,sandere02,2007,1,KCA,AL,24,73,12,23,7,0,2,11.0,0.0,1.0,11,15.0,0.0,1.0,0.0,0.0,2.0
48+
89388,rogerke01,2007,1,DET,AL,1,2,0,0,0,0,0,0.0,0.0,0.0,0,1.0,0.0,0.0,0.0,0.0,0.0
49+
89389,rodriiv01,2007,1,DET,AL,129,502,50,141,31,3,11,63.0,2.0,2.0,9,96.0,1.0,1.0,1.0,2.0,16.0
50+
89396,ramirma02,2007,1,BOS,AL,133,483,84,143,33,1,20,88.0,0.0,0.0,71,92.0,13.0,7.0,0.0,8.0,21.0
51+
89398,piazzmi01,2007,1,OAK,AL,83,309,33,85,17,1,8,44.0,0.0,0.0,18,61.0,0.0,0.0,0.0,2.0,9.0
52+
89400,perezne01,2007,1,DET,AL,33,64,5,11,3,0,1,6.0,0.0,0.0,4,8.0,0.0,0.0,3.0,0.0,2.0
53+
89402,parkch01,2007,1,NYN,NL,1,1,0,0,0,0,0,0.0,0.0,0.0,0,1.0,0.0,0.0,0.0,0.0,0.0
54+
89406,oliveda02,2007,1,LAA,AL,5,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
55+
89410,myersmi01,2007,1,NYA,AL,6,1,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
56+
89411,mussimi01,2007,1,NYA,AL,2,2,0,0,0,0,0,0.0,0.0,0.0,1,0.0,0.0,0.0,0.0,0.0,0.0
57+
89412,moyerja01,2007,1,PHI,NL,33,73,4,9,2,0,0,2.0,0.0,0.0,2,26.0,0.0,0.0,8.0,0.0,1.0
58+
89420,mesajo01,2007,1,PHI,NL,38,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
59+
89421,martipe02,2007,1,NYN,NL,5,9,1,1,1,0,0,0.0,0.0,0.0,0,6.0,0.0,0.0,2.0,0.0,0.0
60+
89425,maddugr01,2007,1,SDN,NL,33,62,2,9,2,0,0,0.0,1.0,0.0,1,19.0,0.0,0.0,9.0,0.0,2.0
61+
89426,mabryjo01,2007,1,COL,NL,28,34,4,4,1,0,1,5.0,0.0,0.0,5,10.0,0.0,0.0,0.0,0.0,1.0
62+
89429,loftoke01,2007,2,CLE,AL,52,173,24,49,9,3,0,15.0,2.0,3.0,17,23.0,0.0,0.0,4.0,2.0,1.0
63+
89430,loftoke01,2007,1,TEX,AL,84,317,62,96,16,3,7,23.0,21.0,4.0,39,28.0,1.0,2.0,2.0,3.0,5.0
64+
89431,loaizes01,2007,1,LAN,NL,5,7,0,1,0,0,0,2.0,0.0,0.0,0,2.0,0.0,0.0,2.0,0.0,1.0
65+
89438,kleskry01,2007,1,SFN,NL,116,362,51,94,27,3,6,44.0,5.0,1.0,46,68.0,2.0,1.0,1.0,1.0,14.0
66+
89439,kentje01,2007,1,LAN,NL,136,494,78,149,36,1,20,79.0,1.0,3.0,57,61.0,4.0,5.0,0.0,6.0,17.0
67+
89442,jonesto02,2007,1,DET,AL,5,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
68+
89445,johnsra05,2007,1,ARI,NL,10,15,0,1,0,0,0,0.0,0.0,0.0,1,7.0,0.0,0.0,2.0,0.0,0.0
69+
89450,hoffmtr01,2007,1,SDN,NL,60,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
70+
89451,hernaro01,2007,2,LAN,NL,22,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
71+
89452,hernaro01,2007,1,CLE,AL,2,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
72+
89460,guarded01,2007,1,CIN,NL,15,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
73+
89462,griffke02,2007,1,CIN,NL,144,528,78,146,24,1,30,93.0,6.0,1.0,85,99.0,14.0,1.0,0.0,9.0,14.0
74+
89463,greensh01,2007,1,NYN,NL,130,446,62,130,30,1,10,46.0,11.0,1.0,37,62.0,4.0,5.0,1.0,1.0,14.0
75+
89464,graffto01,2007,1,MIL,NL,86,231,34,55,8,0,9,30.0,0.0,1.0,24,44.0,6.0,3.0,0.0,2.0,7.0
76+
89465,gordoto01,2007,1,PHI,NL,44,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
77+
89466,gonzalu01,2007,1,LAN,NL,139,464,70,129,23,2,15,68.0,6.0,2.0,56,56.0,4.0,4.0,0.0,2.0,11.0
78+
89467,gomezch02,2007,2,CLE,AL,19,53,4,15,2,0,0,5.0,0.0,0.0,0,6.0,0.0,0.0,1.0,1.0,1.0
79+
89468,gomezch02,2007,1,BAL,AL,73,169,17,51,10,1,1,16.0,1.0,2.0,10,20.0,1.0,0.0,5.0,1.0,5.0
80+
89469,glavito02,2007,1,NYN,NL,33,56,3,12,1,0,0,4.0,0.0,0.0,6,5.0,0.0,0.0,12.0,1.0,0.0
81+
89473,floydcl01,2007,1,CHN,NL,108,282,40,80,10,1,9,45.0,0.0,0.0,35,47.0,5.0,5.0,0.0,0.0,6.0
82+
89474,finlest01,2007,1,COL,NL,43,94,9,17,3,0,1,2.0,0.0,0.0,8,4.0,1.0,0.0,0.0,0.0,2.0
83+
89480,embreal01,2007,1,OAK,AL,4,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
84+
89481,edmonji01,2007,1,SLN,NL,117,365,39,92,15,2,12,53.0,0.0,2.0,41,75.0,2.0,0.0,2.0,3.0,9.0
85+
89482,easleda01,2007,1,NYN,NL,76,193,24,54,6,0,10,26.0,0.0,1.0,19,35.0,1.0,5.0,0.0,1.0,2.0
86+
89489,delgaca01,2007,1,NYN,NL,139,538,71,139,30,0,24,87.0,4.0,0.0,52,118.0,8.0,11.0,0.0,6.0,12.0
87+
89493,cormirh01,2007,1,CIN,NL,6,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
88+
89494,coninje01,2007,2,NYN,NL,21,41,2,8,2,0,0,5.0,0.0,0.0,7,8.0,2.0,0.0,1.0,1.0,1.0
89+
89495,coninje01,2007,1,CIN,NL,80,215,23,57,11,1,6,32.0,4.0,0.0,20,28.0,0.0,0.0,1.0,6.0,4.0
90+
89497,clemero02,2007,1,NYA,AL,2,2,0,1,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
91+
89498,claytro01,2007,2,BOS,AL,8,6,1,0,0,0,0,0.0,0.0,0.0,0,3.0,0.0,0.0,0.0,0.0,2.0
92+
89499,claytro01,2007,1,TOR,AL,69,189,23,48,14,0,1,12.0,2.0,1.0,14,50.0,0.0,1.0,3.0,3.0,8.0
93+
89501,cirilje01,2007,2,ARI,NL,28,40,6,8,4,0,0,6.0,0.0,0.0,4,6.0,0.0,0.0,0.0,0.0,1.0
94+
89502,cirilje01,2007,1,MIN,AL,50,153,18,40,9,2,2,21.0,2.0,0.0,15,13.0,0.0,1.0,3.0,2.0,9.0
95+
89521,bondsba01,2007,1,SFN,NL,126,340,75,94,14,0,28,66.0,5.0,0.0,132,54.0,43.0,3.0,0.0,2.0,13.0
96+
89523,biggicr01,2007,1,HOU,NL,141,517,68,130,31,3,10,50.0,4.0,3.0,23,112.0,0.0,3.0,7.0,5.0,5.0
97+
89525,benitar01,2007,2,FLO,NL,34,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
98+
89526,benitar01,2007,1,SFN,NL,19,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
99+
89530,ausmubr01,2007,1,HOU,NL,117,349,38,82,16,3,3,25.0,6.0,1.0,37,74.0,3.0,6.0,4.0,1.0,11.0
100+
89533,aloumo01,2007,1,NYN,NL,87,328,51,112,19,1,13,49.0,3.0,0.0,27,30.0,5.0,2.0,0.0,3.0,13.0
101+
89534,alomasa02,2007,1,NYN,NL,8,22,1,3,1,0,0,0.0,0.0,0.0,0,3.0,0.0,0.0,0.0,0.0,0.0

data/phonetest.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
679-397-5255
2+
2126660921
3+
212-998-0902
4+
888-888-2222
5+
800-555-1211
6+
800 555 1212
7+
800.555.1213
8+
(800) 555-1214
9+
1-800-555-1215
10+
1(800)555-1216
11+
800-555-1212-1234
12+
800-555-1212x1234
13+
800-555-1212 ext. 1234
14+
work 1-(800) 555.1212 #1234

notes/L-Files.ipynb

Lines changed: 29 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"# Create a file numbers.txt and write the numbers from 0 to 24 there\n",
6565
"f = open(\"numbers.txt\", \"w\")\n",
6666
"for num in range(25):\n",
67-
" f.write(str(num)+'\\n')\n",
67+
" f.write(str(num) + \"\\n\")\n",
6868
"f.close()"
6969
]
7070
},
@@ -158,7 +158,7 @@
158158
"metadata": {},
159159
"outputs": [],
160160
"source": [
161-
"lines = content.split(\"\\n\") # we get back a list of strings\n",
161+
"lines = content.split(\"\\n\") # we get back a list of strings\n",
162162
"print(lines)"
163163
]
164164
},
@@ -169,9 +169,9 @@
169169
"outputs": [],
170170
"source": [
171171
"# here we convert the strings into integers, using a list comprehension\n",
172-
"# we have the conditional to avoid trying to parse the string '' that \n",
172+
"# we have the conditional to avoid trying to parse the string '' that\n",
173173
"# is at the end of the list\n",
174-
"numbers = [int(line) for line in lines if len(line)>0]\n",
174+
"numbers = [int(line) for line in lines if len(line) > 0]\n",
175175
"print(numbers)"
176176
]
177177
},
@@ -192,7 +192,7 @@
192192
"source": [
193193
"#### Exercise 1\n",
194194
"\n",
195-
"* Write a function that reads a file and returns its content as a list of strings (one string per line). Read the file with filename `data/restaurant-names.txt`. If you stored your notebook under `Student_Notebooks` the full filename is `/home/ubuntu/jupyter/NYU_Notes/2-Introduction_to_Python/data/restaurant-names.txt`"
195+
"* Write a function that reads a file and returns its content as a list of strings (one string per line). Read the file with filename `../data/restaurant-names.txt`."
196196
]
197197
},
198198
{
@@ -208,7 +208,7 @@
208208
"source": [
209209
"#### Exercise 2\n",
210210
"\n",
211-
"* Write a function that reads the n-th column of a CSV file and returns its contents. (Reuse the function that you wrote above.) Then reads the file `data/baseball.csv` and return the content of the 5th column (`team`)."
211+
"* Write a function that reads the n-th column of a CSV file and returns its contents. (Reuse the function that you wrote above.) Then reads the file `../data/baseball.csv` and return the content of the 5th column (`team`)."
212212
]
213213
},
214214
{
@@ -224,35 +224,12 @@
224224
"source": [
225225
"#### Exercise 3 \n",
226226
"\n",
227-
"The command below will create a file called `phonetest.txt`. Write code that:\n",
228-
"* Reads the file `phonetest.txt`\n",
227+
"Write code that:\n",
228+
"* Reads the file `../data/phonetest.txt`\n",
229229
"* Write a function that takes as input a string, and removes any non-digit characters\n",
230230
"* Print out the \"clean\" string, without any non-digit characters"
231231
]
232232
},
233-
{
234-
"cell_type": "code",
235-
"execution_count": null,
236-
"metadata": {},
237-
"outputs": [],
238-
"source": [
239-
"%%file phonetest.txt\n",
240-
"679-397-5255\n",
241-
"2126660921\n",
242-
"212-998-0902\n",
243-
"888-888-2222\n",
244-
"800-555-1211\n",
245-
"800 555 1212\n",
246-
"800.555.1213\n",
247-
"(800) 555-1214\n",
248-
"1-800-555-1215\n",
249-
"1(800)555-1216\n",
250-
"800-555-1212-1234\n",
251-
"800-555-1212x1234\n",
252-
"800-555-1212 ext. 1234\n",
253-
"work 1-(800) 555.1212 #1234"
254-
]
255-
},
256233
{
257234
"cell_type": "code",
258235
"execution_count": null,
@@ -276,49 +253,33 @@
276253
"outputs": [],
277254
"source": []
278255
},
279-
{
280-
"cell_type": "code",
281-
"execution_count": null,
282-
"metadata": {},
283-
"outputs": [],
284-
"source": []
285-
},
286-
{
287-
"cell_type": "code",
288-
"execution_count": null,
289-
"metadata": {},
290-
"outputs": [],
291-
"source": []
292-
},
293-
{
294-
"cell_type": "code",
295-
"execution_count": null,
296-
"metadata": {},
297-
"outputs": [],
298-
"source": []
299-
},
300256
{
301257
"cell_type": "markdown",
302-
"metadata": {},
258+
"metadata": {
259+
"solution2": "hidden",
260+
"solution2_first": true
261+
},
303262
"source": [
304-
"#### Solution for exercise 4 (with a lot of comments)"
263+
"#### Solution for exercise 3 (with a lot of comments)"
305264
]
306265
},
307266
{
308267
"cell_type": "code",
309268
"execution_count": null,
310-
"metadata": {},
269+
"metadata": {
270+
"solution2": "hidden"
271+
},
311272
"outputs": [],
312273
"source": [
313274
"# this function takes as input a phone (string variable)\n",
314275
"# and prints only its digits\n",
315276
"def clean(phone):\n",
316-
" # We initialize the result variable to be empty. \n",
317-
" # We will append to this variable the digit characters \n",
277+
" # We initialize the result variable to be empty.\n",
278+
" # We will append to this variable the digit characters\n",
318279
" result = \"\"\n",
319280
" # This is a set of digits (as **strings**) that will\n",
320281
" # allow us to filter the characters\n",
321-
" digits = {\"0\",\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\"}\n",
282+
" digits = {\"0\", \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\"}\n",
322283
" # We iterate over all the characters in the string \"phone\"\n",
323284
" # which is a parameter of the function clean\n",
324285
" for c in phone:\n",
@@ -327,20 +288,22 @@
327288
" # if it is, we append it to the result\n",
328289
" result = result + c\n",
329290
" # once we are done we return a string variable with the result\n",
330-
" return result \n",
291+
" return result\n",
331292
"\n",
332-
"# This is an alternative, one-line solution that uses a list \n",
333-
"# comprehension to create the list of acceptable characters, \n",
334-
"# and then uses the join command to concatenate all the \n",
335-
"# characters in the list into a string. Notice that we use \n",
293+
"\n",
294+
"# This is an alternative, one-line solution that uses a list\n",
295+
"# comprehension to create the list of acceptable characters,\n",
296+
"# and then uses the join command to concatenate all the\n",
297+
"# characters in the list into a string. Notice that we use\n",
336298
"# the empty string \"\" as the connector\n",
337299
"def clean_oneline(phone):\n",
338-
" digits = {\"0\",\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\"}\n",
300+
" digits = {\"0\", \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\"}\n",
339301
" return \"\".join([c for c in phone if c in digits])\n",
340302
"\n",
303+
"\n",
341304
"# your code here\n",
342305
"# We open the file\n",
343-
"f = open(\"phonetest.txt\", \"r\")\n",
306+
"f = open(\"../data/phonetest.txt\", \"r\")\n",
344307
"# We read the content using the f.read() command\n",
345308
"content = f.read()\n",
346309
"# Close the file\n",
@@ -351,16 +314,6 @@
351314
"for line in lines:\n",
352315
" print(line, \"==>\", clean(line))"
353316
]
354-
},
355-
{
356-
"cell_type": "code",
357-
"execution_count": null,
358-
"metadata": {},
359-
"outputs": [],
360-
"source": [
361-
"# Let's clean up\n",
362-
"!rm phonetest.txt"
363-
]
364317
}
365318
],
366319
"metadata": {
@@ -379,7 +332,7 @@
379332
"name": "python",
380333
"nbconvert_exporter": "python",
381334
"pygments_lexer": "ipython3",
382-
"version": "3.5.2"
335+
"version": "3.8.2"
383336
}
384337
},
385338
"nbformat": 4,

0 commit comments

Comments
 (0)