Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Math python question
#6
my interpreation of this task:

from itertools import permutations

res = []
nums = [1,2,3,4]
not_allowed = [(1,2),(2,3),(3,4)]

for perm in permutations(nums,2):
    if perm not in not_allowed:
        res.append(perm)
print(res)
Output:
[(1, 3), (1, 4), (2, 1), (2, 4), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)]
Reply


Messages In This Thread
Math python question - by Deonvek - Apr-05-2023, 02:04 AM
RE: Math python question - by deanhystad - Apr-05-2023, 03:10 AM
RE: Math python question - by Gribouillis - Apr-05-2023, 06:40 AM
RE: Math python question - by ibreeden - Apr-05-2023, 07:37 AM
RE: Math python question - by deanhystad - Apr-05-2023, 05:35 PM
RE: Math python question - by lothar - Apr-05-2023, 08:42 PM
RE: Math python question - by deanhystad - Apr-05-2023, 09:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to do "fixed size" (wrapping) math in Python? AlexanderWulf 13 2,216 Jul-19-2023, 04:13 PM
Last Post: deanhystad
  math.log versus math.log10 stevendaprano 10 2,646 May-23-2022, 08:59 PM
Last Post: jefsummers
  Math Package in python Uma 1 1,588 Dec-12-2021, 02:01 PM
Last Post: jefsummers
  Why getting ValueError : Math domain error in trig. function, math.asin() ? jahuja73 3 3,974 Feb-24-2021, 05:09 PM
Last Post: bowlofred
  "SyntaxError: invalid syntax" running code in Doing Math With Python b saucerdesigner 2 2,829 Nov-03-2020, 04:23 PM
Last Post: saucerdesigner
  Programming Difficult math in Python Huntern 6 4,971 Oct-17-2019, 06:32 AM
Last Post: Huntern
  python 3 math formulas where to use () Python101 1 2,381 Jun-09-2019, 09:54 PM
Last Post: micseydel
  Python modeling a math solution Masterwoot 1 2,340 Mar-01-2019, 08:50 AM
Last Post: buran
  Python math error nadirdogan 3 3,512 Feb-11-2018, 10:56 AM
Last Post: nadirdogan
  Math problem python Dhaval 1 3,025 Jun-05-2017, 10:28 AM
Last Post: wavic

Forum Jump:

User Panel Messages

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