This answer requires a dash list manipulation library. Before attacking your problem, it is helpful to find the length of the longest list. The first way I came is to:
(require 'dash) (require 'dash-functional) (length (-max-by (-on '> 'length) (list xy))) ; 4
-on is a smart function from the dash-functional package that takes a comparator, a key for comparison and returns which is compared with this key. Therefore (-max-by (-on '> 'length) xs) finds an element in xs whose length is large. But this expression is too clever for itself, and dash-functional only works in Emacs 24 because of lexical reach. Let's rewrite it, inspired by the Python solution :
(-max (-map 'length (list xy))) ; 4
To take the first n elements from an infinite loop list do (-take n (-cycle xs)) . Therefore, to create an alist, where elements from the smaller list are cyclical, write:
(let ((len (-max (-map 'length (list xy))))) (flet ((cycle (xs) (-take len (-cycle xs)))) (-zip (cycle x) (cycle y)))) ; (("a" . "1") ("b" . "2") ("c" . "3") ("a" . "4"))
source share