Communauté Eggdrop
Combinaison de listes - Version imprimable

+- Communauté Eggdrop (https://forum.eggdrop.fr)
+-- Forum : Eggdrop et TCL (https://forum.eggdrop.fr/forumdisplay.php?fid=8)
+--- Forum : Bouts de Scripts (https://forum.eggdrop.fr/forumdisplay.php?fid=17)
+--- Sujet : Combinaison de listes (/showthread.php?tid=1469)



Combinaison de listes - CrazyCat - 29/11/2013

Suite à proc Tcl : generation : nbre listes variables avec nbre elem variables, je diffuse ici la petite fonction de combinaison de listes:
tcl
proc combination {head args} {
   if {[llength $args]==0} { return $head }
   set tail [eval combination $args]
   foreach a $head {
      foreach b $tail {
         lappend out [concat $a $b]
      }
   }
   lappend out
   return $out
}



Cette procédure nécessite de recevoir au moins une liste en argument.
Utilisation :
tcl
set l1 { "abc1" "abc2" "abc3" }
set l2 { "def1" "def2" }
set l3 { "ghi1" "ghi2" "ghi3" }
 
putlog [combination $l1 $l2 $l3]