0
私はpython 2.7 iter.productを使用して3つのデータセットのデカルト積を生成しています。itertools.productによって生成されたデータセットにラベルを追加する
これは3つのネストされたループと同じです。しかし、ループに入る前に、ラベル "Fruit Type:"と "Tree Type:"を印刷したいと思います。
これを行うにはどうすればいいですか?私はデカルトを生成できます。そのラベルを後処理で追加しますが、itertoolsを使用してメモリーのフットプリントを削減する目的を破ることはありませんか?
出力はこれが道である
*************************************** Fruit Type: apple *************************************** --------------------------------------- Tree Type: ash --------------------------------------- fruit is apple, tree is ash, animal is dog fruit is apple, tree is ash, animal is cat fruit is apple, tree is ash, animal is horse --------------------------------------- Tree Type: oak --------------------------------------- fruit is apple, tree is oak, animal is dog fruit is apple, tree is oak, animal is cat fruit is apple, tree is oak, animal is horse --------------------------------------- Tree Type: beech --------------------------------------- fruit is apple, tree is beech, animal is dog fruit is apple, tree is beech, animal is cat fruit is apple, tree is beech, animal is horse --------------------------------------- Tree Type: ash --------------------------------------- *************************************** Fruit Type: orange *************************************** --------------------------------------- Tree Type: ash --------------------------------------- fruit is orange, tree is ash, animal is dog fruit is orange, tree is ash, animal is cat fruit is orange, tree is ash, animal is horse --------------------------------------- Tree Type: oak --------------------------------------- fruit is orange, tree is oak, animal is dog fruit is orange, tree is oak, animal is cat fruit is orange, tree is oak, animal is horse --------------------------------------- Tree Type: beech --------------------------------------- fruit is orange, tree is beech, animal is dog fruit is orange, tree is beech, animal is cat fruit is orange, tree is beech, animal is horse *************************************** Fruit Type: pear *************************************** --------------------------------------- Tree Type: ash --------------------------------------- fruit is pear, tree is ash, animal is dog fruit is pear, tree is ash, animal is cat fruit is pear, tree is ash, animal is horse --------------------------------------- Tree Type: oak --------------------------------------- fruit is pear, tree is oak, animal is dog fruit is pear, tree is oak, animal is cat fruit is pear, tree is oak, animal is horse --------------------------------------- Tree Type: beech --------------------------------------- fruit is pear, tree is beech, animal is dog fruit is pear, tree is beech, animal is cat fruit is pear, tree is beech, animal is horse