In [27]:
##STEP 1

with open("song1.txt","r") as f:
    lines = f.readlines()   # readlines creates a list of strings
#print(lines)
pos_dict = {}
pos = 1
for line in lines:
    words = line.strip().split()
    #print(words)
    for index,word in enumerate(words):
        word = word.upper()
        if index == len(words)-1:
            pos2 = -pos
        else:
            pos2 = pos
        if word in pos_dict:
            pos_dict[word] = pos_dict[word] + [pos2]
        else:
            pos_dict[word] = [pos2]
        pos = pos + 1
print(pos_dict)
{'WHAT': [1, 4, 7], 'HAVE': [2, 5, 8], 'I': [-3, -6, 9], 'DONE': [10], 'TO': [11], 'DESERVE': [12], 'THIS': [-13]}
In [16]:
s = " \t\t  hello \t \n world \n\n "
#s.rstrip()
#s.lstrip()
s.strip()
Out[16]:
'hello \t \n world'

white space characters on the keyboard: space, tab, newline

In [25]:
words = ["WHAT","HAVE","I"]
for index,word in enumerate(words):
    print(word)
WHAT
HAVE
I
In [ ]:
for word in words:
    ???

for index,word in enumerate(words):
    ???
In [26]:
nums = [1,5,4,3]
sum = 0
for num in nums:
    sum = sum + num
print(sum)
13
In [ ]: