table collection special methods special method usage description __contains__(selfxx in returns true if is in sequence or if is key in mapping __delitem__(selfkdel [kdeletes the -th item of sequence or the item with key in mapping __getitem__(selfky[kreturns the -th item of sequence or the value for key in mapping __iter__(selffor in yreturns an iterator for sequence ' pass items or mapping ' keys __len__(selflen(y__reversed__(selfreversed(yreturns backward iterator for sequence ' items or mapping ' keys __setitem__(selfkvy[kv returns the number of items in sets the -th item of sequence or the value for key in mapping yto def __setitem__(selfcoordinatecolor)assert len(coordinate= "coordinate should be -tupleif (not ( <coordinate[ self widthor not ( <coordinate[ self height))raise coordinateerror(str(coordinate)if color =self __backgroundself __data pop(tuple(coordinate)noneelseself __data[tuple(coordinate)color self __colors add(colorif the user sets coordinate' value to the background color we can simply delete the corresponding dictionary item since any coordinate not in the dictionary is assumed to have the background color we must use dict pop(and give dummy second argument rather than use del because doing so avoids keyerror being raised if the key (coordinateis not in the dictionary if the color is different from the background colorwe set it for the given coordinate and add it to the set of the unique colors used by the image def __delitem__(selfcoordinate)assert len(coordinate= "coordinate should be -tupleif (not ( <coordinate[ self widthor not ( <coordinate[ self height))raise coordinateerror(str(coordinate)self __data pop(tuple(coordinate)none