-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfn3.py
More file actions
26 lines (22 loc) · 912 Bytes
/
fn3.py
File metadata and controls
26 lines (22 loc) · 912 Bytes
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
#Determine the longest word in the enable1 dictionary that can be formed.
#I have some problem with this one, as though I'm not familiar with urllib2.
from urllib2 import urlopen
def longest(string, file):
longest_string = ""
qlen = string.count('?')
f = urlopen("https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/dotnetperls-controls/enable1.txt").read()
for word in file.split():
strlen = len(word)
w = list(word)
for letter in string:
if letter != '?':
loc = w.index(letter) if letter in w else -1
if loc != -1:
del(w[loc])
strlen -= 1
else:
strlen -=1
if strlen <= 0:
if len(word)>len(longest_string):
longest_string = word
return longest_string