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 reverse key order.
def ksort(d): return [(k,d[k]) for k in sorted(d.keys(), reverse=True)] krsort(PHP 4, PHP 5) krsort — Sort an array by key in reverse order Description
bool krsort
( array &$array
[, int $sort_flags= SORT_REGULAR
] )
Sorts an array by key in reverse order, maintaining key to data correlations. This is useful mainly for associative arrays. Parameters
Return ValuesReturns TRUE on success or FALSE on failure. Examples
Example #1 krsort() example
<?php The above example will output: d = lemon c = apple b = banana a = orange
|
more
Recently updated
more
Most requested
more
Last requests
|