Hallo, ich frage mich nur, wie berechnen wir kartesischen Produkt (intertools.product (* somelist)) aber ohne das Komma zu drucken?Ermitteln Cartasian Produkt Itertools.Product ohne Komma (Delimiter)
ICH MÖCHTE ETWAS ETWAS DRUCKEN!
So, if the first input is of the form: A, B, .. X
and the second is of the form: 1, 2, .. n
the output would be of the form:
["A 1", "A 2", .. "An", "B 1", "B 2", .. "Bn", .. "X 1", "X 2", .. "Xn"]
(where the ".." indicates there can be more elements in between).
Here is a more specific case:
For inputs: blue, electric, floating
and: cheese, eel
we would get:
["blue cheese", "electric cheese", "floating cheese", "blue eel",...........
HOWEVER WHEN I DO
listA=[] #Creating a list
listB=[]#Creating a second list
listC=[]
input_listA=input("Enter second comma separated list of int: ")
listA.append(input_listA)
input_listB = input("Enter first comma separated list of strings: ")
listB.append(input_listB)
listC.append(listB)
listC.append(listA)
for i in itertools.product(*listA,*listB):
print(i)
es diesem Ausgang geben:
INPUT: Eingabe zweite kommagetrennte Liste von int: A, B, C erster kommagetrennte Liste von Zeichenfolge eingeben: 1, 2, 3 ('A "," 1 ") (" A ",", ") (" A "," ") (" A "," 2 ") (" A ",", ") (" A "," ") ('A', '3') (',', '1') (',', ',') (',', '') (',', '2') (',', ',') (',', '') (',', '3') ('', '1') (' ', ',') ('', '') ('', ' 2 ') (' ',', ') (' ',' ') (' ',' 3 ') (' B ', ' 1 ') (' B ',', ') (' B ', '')
WIE KANN ICH ES SIE in der richtigen Form Drucken Sie von "A 1", "A 2", .. "An" So entfernen Sie "" und ""
DAS für i in itertools.product (Lista, listB): print ('{} {}'.Format (* i)) IT GIVES ein anderes Ergebnis als YOURS: es ist ein Ergebnis mit COMMAS IST ('') neben dem OTHE A 1 A, A 2 A, A 3 , 1 , , 2 , , 3 B 1 B, B 2 B, B 3 , 1 , , 2 , , 3 C 1 C, C 2 C, C 3 –
@ A.kaisis müssen Sie die andere Änderung auch vornehmen. Erweitern von 'listA' und' listB'. – salparadise
mit ihnen das Ergebnis ist: aa aa aa aa , ein , ein , ein , ein ba ba ba ba , ein , ein , ein , ein ca ca ca ca –