2018年1月8日 星期一

Python 列舉

Python List: Exercise - 18 with Solution
Write a Python program to generate all permutations of a list in Python.
In mathematics, the notion of permutation relates to the act of arranging all the members of a set into some sequence or order, or if the set is already ordered, rearranging (reordering) its elements, a process called permuting. These differ from combinations, which are selections of some members of a set where order is disregarded.
In the following image each of the six rows is a different permutation of three distinct balls.
Pictorial Presentation
Different permutation of three distinct balls
Sample Solution:-
Python Code:
import itertools
print(list(itertools.permutations([1,2,3])))

Sample Output:
[(1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)] 


沒有留言:

張貼留言

WOKWI ESP32 LED Control , Node-Red MQTT SQLITE  

WOKWI ESP32 LED Control ,  Node-Red  MQTT SQLITE   const char broker[] = "test.mosquitto.org" ; //const char broker[] = "br...