Untitled

 avatar
unknown
python
4 years ago
1.1 kB
8
Indexable
# the first question was
#
# give a list of tuple ex. [(1, 1), (1, 2), (1, 3)]
# create a function that does the following
#
# the first number is the procedure
# and the 2nd number is what you put inside of your storage of choice (list or dictionary)
# 
# 1 = add to the array
# 2 = delete item from array
# 3 = give back any element in array that is equal to the 2nd integer


def act(tupleList):
    actList = []
    for tuple in tupleList:
        if tuple[0] == 1:
            actList.append(tuple[1])
        if tuple[0] == 2 and tuple[1] in actList:
            while tuple[1] in actList:
                actList.remove(tuple[1])
        if tuple[0] == 3 and tuple[1] in actList:
            indexes = []
            for indx in range(len(actList)):
                if actList[indx] == tuple[1]:
                    indexes.append(indx)
            print(f"{tuple[1]} is currently written to the following indexes: {indexes}")
    return actList

if __name__ == "__main__":
    tupes = [(1, 1), (1, 5), (1, 8), (1, 6), (1, 8), (2, 6), (1, 8), (1, 2), (3, 8)]
    act(tupes)
Editor is loading...