This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def namedlist(typename, field_names): | |
"""Returns a new subclass of list with named fields. | |
>>> Point = namedlist('Point', ('x', 'y')) | |
>>> Point.__doc__ # docstring for the new class | |
'Point(x, y)' | |
>>> p = Point(11, y=22) # instantiate with positional args or keywords | |
>>> p[0] + p[1] # indexable like a plain list | |
33 | |
>>> x, y = p # unpack like a regular list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class AnyKeyArray implements ArrayAccess, Iterator, Countable { | |
private $values = array(); | |
// ArrayAccess | |
function offsetSet($key, $value) { | |
$this->values[serialize($key)] = $value; | |
} | |