PHP » PYTHON |
login |
register |
about
|
In Python, a dictionary (i.e. associative array) is not ordered, so it is not possible to "modify the order" of the dictionary like you can in PHP. Instead, we return a new list of the (key, value) pairs of the dictionary sorted in key order.
def ksort(d): return [(k,d[k]) for k in sorted(d.keys())] ksort(PHP 4, PHP 5) ksort — Sort an array by key Description
bool ksort
( array &$array
[, int $sort_flags= SORT_REGULAR
] )
Sorts an array by key, maintaining key to data correlations. This is useful mainly for associative arrays. Parameters
Return ValuesReturns TRUE on success or FALSE on failure. Changelog
Examples
Example #1 ksort() example
<?php The above example will output: a = orange b = banana c = apple d = lemon
See Also
|
more
Recently updated
more
Most requested
more
Last requests
|