+ 6
Help with code.
Can someone please tell me how can I run this code without error? https://code.sololearn.com/cBxzV5USlHL5/?ref=app
8 odpowiedzi
+ 2
How 'bout this:
def __getitem__(self, arg):
a, index = arg
return self.cont[index +a+ random.randint(-1, 1)]
print(vague_list[2,1])
print(vague_list[2,2])
+ 7
just remove the variable "a" and be aware you can get a list index out of range
else you can do this:
def __get_item__(self, item):
return self.cont[item[0] + item[1] + .......]
and use it like this :
vague[2,1]
+ 6
But I want "a" as second attribute to be there for no reason and code to run normal.
+ 6
You're welcome :-) i don't know if it's possible to keep both index and a variable... but with list it's possible to send several values to the function !
+ 5
Thanks a lot @Glozi 30
+ 5
@Tobi, exactly my thinking! :)
(still don't know what the a var does ;)
+ 4
What is the variable 'a' supposed to do?
+ 4
Thank you @Tobi
(@Kuba Siekierzyński var "a" is there for no reason just as second attribute)