9 min, including test
import math
def nthperm(li, n):
n -= 1
s = len(li)
res = []
if math.factorial(s) <= n:
return None
for x in range(s-1,-1,-1):
f = math.factorial(x)
d = n / f
n -= d * f
res.append(li[d])
del(li[d])
return res
#now that's fast...
nthperm(range(40), 123456789012345678901234567890)
Related Contents:
- Basics of recursion in Python
- How to do a recursive sub-folder search and return files in a list?
- Python recursion with list returns None [duplicate]
- Making all possible combinations of a list
- Flattening a list recursively [duplicate]
- How to find common elements in list of lists?
- Confusing […] List in Python: What is it?
- Accessing the index in ‘for’ loops
- How do I convert two lists into a dictionary?
- How to group dataframe rows into list in pandas groupby
- Why does “return list.sort()” return None, not the list?
- How does assignment work with list slices?
- How to define a two-dimensional array?
- Identify groups of continuous numbers in a list
- How to check if a string is a substring of items in a list of strings?
- What is the difference between `sorted(list)` vs `list.sort()`?
- Copying nested lists in Python
- Removing elements that have consecutive duplicates
- How slow is Python’s string concatenation vs. str.join?
- Merge lists that share common elements
- Pandas DataFrame to List of Dictionaries
- In Python, what is the difference between “.append()” and “+= []”?
- Creating a list of dictionaries results in a list of copies of the same dictionary
- Python – TypeError: ‘int’ object is not iterable
- Alphabet range in Python
- Find nearest indices for one array against all values in another array – Python / NumPy
- How do I multiply each element in a list by a number?
- Finding first and last index of some value in a list in Python
- What is the inverse function of zip in python? [duplicate]
- How to find the min/max value of a common key in a list of dicts?
- Modifying a list inside a function
- Explicitly select items from a list or tuple
- Filtering a list based on a list of booleans
- How to remove multiple items from a list in just one statement?
- How to access the elements of a 2D array?
- Matplotlib Graph Data
- How to get the n next values of a generator into a list
- How to append multiple values to a list in Python
- appending list but error ‘NoneType’ object has no attribute ‘append’ [duplicate]
- What is the ‘pythonic’ equivalent to the ‘fold’ function from functional programming?
- Why does a for-loop with pop-method (or del statement) not iterate over all list elements [duplicate]
- Deleting node in BST Python
- What is time complexity of a list to set conversion?
- Big-O of list slicing
- Replacing a sublist with another sublist in python
- How to override the slice functionality of list in its derived class
- Difference between using [] and list() in Python
- How to flatten a hetrogenous list of list into a single list in python? [duplicate]
- Using a dict to translate numbers to letters in python
- How to convert a set to a list in python?