Skip to content

Instantly share code, notes, and snippets.

@iorlas
Created February 25, 2011 01:46
Show Gist options
  • Save iorlas/843267 to your computer and use it in GitHub Desktop.
Save iorlas/843267 to your computer and use it in GitHub Desktop.
http://common-lisp.net/project/iterate/#examples
(loop with max-elt = nil
with max-key = 0
for elt in list-of-lists
for key = (length elt) do
(when (> key max-key)
(setq max-elt elt
max-key key))
finally (return max-elt))
(iterate (for elt in list-of-lists)
(finding elt maximizing (length elt)))
****************************
* Directly to Python: *
****************************
max-elt = None
max-key = 0
for elt in list-of-lists:
for key in range(len(elf):
if key > max-key:
max-elt = elf
max-key = key
return max-elt
#There is no similar func to "finding maximizing" at all, you can just use simple max-finding alg
tmp = []
for elt in list-of-lists:
if len(elt) > len(tmp):
tmp = elt
****************************
* Using Python power: *
****************************
#it may be shorter, but it already looks better
max-elt = None
max-key = 0
for elt in list-of-lists:
current-max-var = max(elt)
if current-max-var > max-key:
max-key, max-elt = current-max-var, elt
#no comments
max(list-of-lists)
#you can use any you function for working like it done in CL iterate
max(list-of-lists, key=len)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment