Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Python Multiplication

Name: OP !rZq6XkhESk 2013-11-07 9:48

I want to know how to multiply two sets of numbers together in python. How do I do this?

For example say I have:
set1 = (x1, x2, x3)
set2 = (y1, y2, y3)

How would I get python to multiply these sets and have the result be:

set1 * set2 = (x1*y1,x2*y2, x3*y3)

Name: Anonymous 2013-11-07 9:49

xD

Name: Anonymous 2013-11-07 9:49

xD

Name: Anonymous 2013-11-07 9:49

xD

Name: Anonymous 2013-11-07 9:50

xD

Name: Anonymous 2013-11-07 9:50

xD

Name: Anonymous 2013-11-08 2:03

Sets are immutable.
a = {1,2,3}
b = {4,5,6}
alist = list(a)
blist = list(b)
clist = []
i = 0
while i < len(alist) and i < len(blist):
    clist.append(alist[i]* blist[i])
    i += 1
c =set(clist)

Name: Anonymous 2013-11-08 5:10

>>7
Gay.

import operator
define multiply_sets(a, b): map(operator.__mul__, a, b)

Don't change these.
Name: Email:
Entire Thread Thread List