print "Start entering words:"
previous = []
word = raw_input()
while word not in previous:
previous.append(word)
word = raw_input()
print "You already entered " + word + "."
print "You listed", len(previous), "distinct words."
(click to see it run live)
(6 points)
def acronym(phrase):
a = ''
for word in phrase.split():
a += word[0]
return a.upper()
(click
to see it run live)
Or, for those who like to use list comprehensions,
def acronym(phrase):
return ''.join([word[0] for word in phrase.split()]).upper()
def sliding(word, num=3):
for i in range(len(word)+1-num):
print ' '*i + word[i:i+num]
(click to see it run live)
def pairSum(data, goal):
for a in range(len(data)-1):
for b in range(a+1, len(data)):
if data[a] + data[b] == goal:
return True
return False