Your code works just fine, provided you actually pass in a list of 3 elements:
>>> class Sentence(object):
... def __init__(self, subject, verb, object):
... self.subject = subject[1]
... self.verb = verb[1]
... self.object = object[1]
...
>>> sentence_list = [('noun', 'I'), ('verb', 'kill'), ('noun', 'princess')]
>>> Sentence(*sentence_list)
<__main__.Sentence object at 0x10043c0d0>
>>> del sentence_list[-1]
>>> Sentence(*sentence_list)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: __init__() takes exactly 4 arguments (3 given)
Note the error message here; __init__
takes four arguments, including self
.
Ergo, it is your sentence_list
value that is at fault here, not your technique.