3 ms·
Yes, it is Python. Python has become a lingua franca in the programming world, and you'd be well-advised to learn it. It creates a list but that is inconsequent
by bjourne 10y ago
Yes, it is Python. Python has become a lingua franca in the programming world, and you'd be well-advised to learn it. It creates a list but that is inconsequential. Here is the fixed code (to actually generate permutations) and examples:
>>> from itertools import *
>>> [s for s in product(range(2), repeat=2) if len(set(s))==2]
[(0, 1), (1, 0)]
>>> [s for s in product(range(3), repeat=3) if len(set(s))==3]
[(0, 1, 2), (0, 2, 1), (1, 0, 2), (1, 2, 0), (2, 0, 1), (2, 1, 0)]
>>> len([s for s in product(range(4), repeat=4) if len(set(s))==4])
24
>>> len([s for s in product(range(5), repeat=5) if len(set(s))==5])
120
- pron 10y ago> Python has become a lingua franca in the programming world I don't think so. Probably depends on your section of the industry. In mine, C, Java and Matlab are all better known than Python. > you'd be well-advised to learn it I did; a few times, actually. I just keep forgetting because I never get an opportunity to use it. Once you've used well over 10 languages, you don't even try to maintain your skills as that would be a waste of time. You just relearn the language next time you need it, especially as popular languages come and go. Standard mathematical notation, however, has been with us, pretty much unchanged, for about 100 years now. In any event, you can't express in Python nearly everything you can express in standard mathematical notation, unless Python has gained some features that allow it to express uncomputable objects since last time I used it. Does the itertools library support infinite sequences? How about uncountable sets?