Skip to content

Instantly share code, notes, and snippets.

@starenka
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save starenka/9466644 to your computer and use it in GitHub Desktop.
Save starenka/9466644 to your computer and use it in GitHub Desktop.
ph what p?
'''
<?php
$array = array_fill(0,10000, "ahoj");
$count = 0;
$length = 0;
foreach($array as $item) {
$count += 1;
$length += strlen($item);
}
echo "count: $count, length: $length";
'''
>>> arr = ['ahoj'] * 10000
>>> 'count:', len(arr), 'length:', reduce(lambda x, y: x + len(y), arr, 0)
('count:', 10000, 'length:', 40000)
@AoJ
Copy link

AoJ commented Mar 10, 2014

python je prostě čitelnější :)

arr = ("ahoj" for num in [0...10000])
console.log "count: #{arr.length}, length: " + arr.reduce (c,i) -> 
  c += i.length
, 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment