Python Forum
Multiplying between two values
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiplying between two values
#5
>>> [(xitem, yitem) for xitem in x for yitem in y if xitem * yitem < 10]
[(1, 5), (1, 3.33), (1, 2.5), (1, 2), (2, 3.33), (2, 2.5), (2, 2), (3, 3.33), (3, 2.5), (3, 2), (4, 2)]
Or if you didn't want to roll the loop yourself, you could use product and operator modules...

>>> from itertools import product
>>> from operator import mul
>>> [p for p in product(x,y) if mul(*p) < 10]
[(1, 5), (1, 3.33), (1, 2.5), (1, 2), (2, 3.33), (2, 2.5), (2, 2), (3, 3.33), (3, 2.5), (3, 2), (4, 2)]
Reply


Messages In This Thread
Multiplying between two values - by doug2019 - Oct-19-2020, 10:14 PM
RE: Multiplying between two values - by bowlofred - Oct-19-2020, 10:21 PM
RE: Multiplying between two values - by jefsummers - Oct-19-2020, 11:14 PM
RE: Multiplying between two values - by doug2019 - Oct-19-2020, 11:17 PM
RE: Multiplying between two values - by bowlofred - Oct-19-2020, 11:31 PM
RE: Multiplying between two values - by deanhystad - Oct-20-2020, 04:42 AM
RE: Multiplying between two values - by DeaD_EyE - Oct-20-2020, 08:03 AM
RE: Multiplying between two values - by doug2019 - Oct-20-2020, 05:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  List structure lost when multiplying Protonn 2 2,306 Apr-23-2020, 04:16 AM
Last Post: buran
  multiplying elements in a list Olavv 3 3,483 Feb-27-2020, 04:55 PM
Last Post: DeaD_EyE
  Multiplying two lists to make an array pberrett 15 6,002 May-15-2019, 02:22 AM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020