+ 6

Help with code.

Can someone please tell me how can I run this code without error? https://code.sololearn.com/cBxzV5USlHL5/?ref=app

29th Apr 2017, 8:57 PM
Tim Thuma
Tim Thuma - avatar
8 Respostas
+ 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])
29th Apr 2017, 9:43 PM
Tob
Tob - avatar
+ 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]
29th Apr 2017, 9:21 PM
Glozi30
Glozi30 - avatar
+ 6
But I want "a" as second attribute to be there for no reason and code to run normal.
29th Apr 2017, 9:27 PM
Tim Thuma
Tim Thuma - avatar
+ 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 !
29th Apr 2017, 9:37 PM
Glozi30
Glozi30 - avatar
+ 5
Thanks a lot @Glozi 30
29th Apr 2017, 9:35 PM
Tim Thuma
Tim Thuma - avatar
+ 5
@Tobi, exactly my thinking! :) (still don't know what the a var does ;)
29th Apr 2017, 9:57 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 4
What is the variable 'a' supposed to do?
29th Apr 2017, 9:04 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 4
Thank you @Tobi (@Kuba Siekierzyński var "a" is there for no reason just as second attribute)
30th Apr 2017, 6:51 AM
Tim Thuma
Tim Thuma - avatar