0
How to calculate the sum of 2 dice?
My code: def myDiceSum(numberofside, numberofdice, thrown): for i in range(numberofside): t=[(rd.randint(1,numberofside)) for i in range(anzahlWuerfe)] For exampe: 1.iteration t=[1,4,3,1,5] 2.iteration t=[2,5,6,4,1] How can I add the elements of the 2 list with each other?
4 Answers
0
Look into the zip() method - it should help you here.
0
zip? no no no no...noooooooooooo.
.
use map() and a lambda.
0
rodwynnejones Unless I've misunderstood the point of the question, I feel that using zip() results in some pretty succinct code (see below).
How are you proposing that it should be done?
https://code.sololearn.com/cfscCrd23U69/?ref=app
0
This is what I had in mind:-
t1 =[1, 4, 3, 1, 5]
t2 =[2, 5, 6, 4, 1]
t3 = list(map(lambda a, b: a + b, t1, t2))
print(list(t3))
...but I see you method is more 'straight forward', nice way to do it (and handy to know).