parent
166d6faa9e
commit
bbe98369bd
4 changed files with 61 additions and 8 deletions
@ -0,0 +1,22 @@ |
||||
<?php |
||||
$operator = PyCore::import("operator"); |
||||
$builtins = PyCore::import("builtins"); |
||||
|
||||
function invert_dictionary($obj) { |
||||
return (function() { |
||||
$___ = []; |
||||
$___iter = $obj->items(); |
||||
foreach($___iter as $___i => [$key, $value]) { |
||||
$___[] = [$key, $value]; |
||||
} |
||||
return $___; |
||||
})(); |
||||
} |
||||
|
||||
|
||||
$ages = new PyDict([ |
||||
"Peter" => 10, |
||||
"Isabel" => 11, |
||||
"Anna" => 9, |
||||
]); |
||||
invert_dictionary($ages); |
||||
@ -1,10 +1,9 @@ |
||||
|
||||
def invert_dictionary(obj): |
||||
return { value: key for key, value in obj.items() } |
||||
from math import sqrt |
||||
|
||||
ages = { |
||||
'Peter': 10, |
||||
'Isabel': 11, |
||||
'Anna': 9, |
||||
} |
||||
invert_dictionary(ages) # { 10: 'Peter', 11: 'Isabel', 9: 'Anna' } |
||||
def is_prime(n): |
||||
if n <= 1 or (n % 2 == 0 and n > 2): |
||||
return False |
||||
return all(n % i for i in range(3, int(sqrt(n)) + 1, 2)) |
||||
|
||||
is_prime(11) # True |
||||
|
||||
@ -0,0 +1,9 @@ |
||||
|
||||
from math import sqrt |
||||
|
||||
def is_prime(n): |
||||
if n <= 1 or (n % 2 == 0 and n > 2): |
||||
return False |
||||
return all(n % i for i in range(3, int(sqrt(n)) + 1, 2)) |
||||
|
||||
is_prime(11) # True |
||||
Loading…
Reference in new issue