def makeInverseIndex(strList):
    """
    Input: a list of documents as strings
    Output: a dictionary that maps each word in any document to the set consisting of the
            document ids (ie, the index in the strlist) for all documents containing the word.
    Distinguish between an occurence of a string (e.g. "use") in the document as a word
    (surrounded by spaces), and an occurence of the string as a substring of a word (e.g. "because").
    Only the former should be represented in the inverse index.
    Feel free to use a loop instead of a comprehension.

    Example:
    >>> makeInverseIndex(['hello world','hello','hello cat','hellolot of cats']) == {'hello': {0, 1, 2}, 'cat': {2}, 'of': {3}, 'world': {0}, 'cats': {3}, 'hellolot': {3}}
    True
    """
    index = {}
    for doc_i, doc in dictutil.listrange2dict(strList).items():
        for word in doc.split():
            index[word] = index[word] | {doc_i} if word in index else {doc_i}
            
    return index
import random
import dictutil


## 1: (Task 1) Movie Review
## Task 1
def movie_review(name):
    """
    Input: the name of a movie
    Output: a string (one of the review options), selected at random using randint
    """
    reviews = ["See it!", "A gem!", "Ideological claptrap!", "its awesome", "Don't see it ever", "wow!", "what a joke"]
    return reviews[random.randint(0, len(reviews)-1)]

print("Star wars review: ", movie_review("asdf"))
print("Listrange2dict: ", dictutil.listrange2dict(['A', 'B', 'C']))

## 2: (Task 2) Make Inverse Index
def makeInverseIndex(strlist):
    """
    Input: a list of documents as strings
    Output: a dictionary that maps each word in any document to the set consisting of the
            document ids (ie, the index in the strlist) for all documents containing the word.
    Distinguish between an occurence of a string (e.g. "use") in the document as a word
    (surrounded by spaces), and an occurence of the string as a substring of a word (e.g. "because").
    Only the former should be represented in the inverse index.
    Feel free to use a loop instead of a comprehension.

    Example:
    >>> makeInverseIndex(['hello world','hello','hello cat','hellolot of cats']) == {'hello': {0, 1, 2}, 'cat': {2}, 'of': {3}, 'world': {0}, 'cats': {3}, 'hellolot': {3}}
    True
Beispiel #3
0
math.sqrt(3)
#Task 0.6.2
from random import randint
randint(1,10)
def movie_review(name): return ["See it","A gem!","Ideologcial claptrap!"][randint(0,2)]
movie_review('hello')

#Task 0.6.3
import dictutil
dictutil.dict2list({'a':'A','b':'B','c':'C'},['b','c','a'])
dictutil.list2dict(['A','B','C'], ['a','b','c'])

from importlib import reload
reload(dictutil)
#Task 0.6.4
dictutil.listrange2dict(['A','B','C'])

for x in {1,2,3}:
    print(x)

v = [1,2,0]
i = 0
while v[i] == 0:
    print(v[i])
    i = i + 1
if True : print('True')

for x in [1,2,3]:
    y = x * x
    print(y)
x