I'm currently trying to iterate over all combinations of 4 digits on a URL but it seems to be only doing a handful of them (instead of 10,000). Any ideas why?
import requests
from itertools import combinations
x = [1,2,3,4,5,6,7,8,9,0]
for c in combinations(x, 4):
print(c)
URL = "http://www.google.com/" + str(c)
r = requests.get(url = URL)
print(r.content)
It only does the following permutations:
(1, 2, 3, 4)
(1, 2, 3, 5)
(1, 2, 3, 6)
(1, 2, 3, 7)
(1, 2, 3, 8)
(1, 2, 3, 9)
(1, 2, 3, 0)
(1, 2, 4, 5)
(1, 2, 4, 6)
(1, 2, 4, 7)
(1, 2, 4, 8)
(1, 2, 4, 9)
(1, 2, 4, 0)
(1, 2, 5, 6)
(1, 2, 5, 7)
(1, 2, 5, 8)
(1, 2, 5, 9)
(1, 2, 5, 0)
(1, 2, 6, 7)
(1, 2, 6, 8)
(1, 2, 6, 9)
(1, 2, 6, 0)
(1, 2, 7, 8)
(1, 2, 7, 9)
(1, 2, 7, 0)
(1, 2, 8, 9)
(1, 2, 8, 0)
(1, 2, 9, 0)
(1, 3, 4, 5)
(1, 3, 4, 6)
(1, 3, 4, 7)
(1, 3, 4, 8)
(1, 3, 4, 9)
(1, 3, 4, 0)
(1, 3, 5, 6)
(1, 3, 5, 7)
(1, 3, 5, 8)
(1, 3, 5, 9)
(1, 3, 5, 0)
(1, 3, 6, 7)
(1, 3, 6, 8)
(1, 3, 6, 9)
(1, 3, 6, 0)
(1, 3, 7, 8)
(1, 3, 7, 9)
(1, 3, 7, 0)
(1, 3, 8, 9)
(1, 3, 8, 0)
(1, 3, 9, 0)
(1, 4, 5, 6)
(1, 4, 5, 7)
(1, 4, 5, 8)
(1, 4, 5, 9)
(1, 4, 5, 0)
(1, 4, 6, 7)
(1, 4, 6, 8)
(1, 4, 6, 9)
(1, 4, 6, 0)
(1, 4, 7, 8)
(1, 4, 7, 9)
(1, 4, 7, 0)
(1, 4, 8, 9)
(1, 4, 8, 0)
(1, 4, 9, 0)
(1, 5, 6, 7)
(1, 5, 6, 8)
(1, 5, 6, 9)
(1, 5, 6, 0)
(1, 5, 7, 8)
(1, 5, 7, 9)
(1, 5, 7, 0)
(1, 5, 8, 9)
(1, 5, 8, 0)
(1, 5, 9, 0)
(1, 6, 7, 8)
(1, 6, 7, 9)
(1, 6, 7, 0)
(1, 6, 8, 9)
(1, 6, 8, 0)
(1, 6, 9, 0)
(1, 7, 8, 9)
(1, 7, 8, 0)
(1, 7, 9, 0)
(1, 8, 9, 0)
(2, 3, 4, 5)
(2, 3, 4, 6)
(2, 3, 4, 7)
(2, 3, 4, 8)
(2, 3, 4, 9)
(2, 3, 4, 0)
(2, 3, 5, 6)
(2, 3, 5, 7)
(2, 3, 5, 8)
(2, 3, 5, 9)
(2, 3, 5, 0)
(2, 3, 6, 7)
(2, 3, 6, 8)
(2, 3, 6, 9)
(2, 3, 6, 0)
(2, 3, 7, 8)
(2, 3, 7, 9)
(2, 3, 7, 0)
(2, 3, 8, 9)
(2, 3, 8, 0)
(2, 3, 9, 0)
(2, 4, 5, 6)
(2, 4, 5, 7)
(2, 4, 5, 8)
(2, 4, 5, 9)
(2, 4, 5, 0)
(2, 4, 6, 7)
(2, 4, 6, 8)
(2, 4, 6, 9)
(2, 4, 6, 0)
(2, 4, 7, 8)
(2, 4, 7, 9)
(2, 4, 7, 0)
(2, 4, 8, 9)
(2, 4, 8, 0)
(2, 4, 9, 0)
(2, 5, 6, 7)
(2, 5, 6, 8)
(2, 5, 6, 9)
(2, 5, 6, 0)
(2, 5, 7, 8)
(2, 5, 7, 9)
(2, 5, 7, 0)
(2, 5, 8, 9)
(2, 5, 8, 0)
(2, 5, 9, 0)
(2, 6, 7, 8)
(2, 6, 7, 9)
(2, 6, 7, 0)
(2, 6, 8, 9)
(2, 6, 8, 0)
(2, 6, 9, 0)
(2, 7, 8, 9)
(2, 7, 8, 0)
(2, 7, 9, 0)
(2, 8, 9, 0)
(3, 4, 5, 6)
(3, 4, 5, 7)
(3, 4, 5, 8)
(3, 4, 5, 9)
(3, 4, 5, 0)
(3, 4, 6, 7)
(3, 4, 6, 8)
(3, 4, 6, 9)
(3, 4, 6, 0)
(3, 4, 7, 8)
(3, 4, 7, 9)
(3, 4, 7, 0)
(3, 4, 8, 9)
(3, 4, 8, 0)
(3, 4, 9, 0)
(3, 5, 6, 7)
(3, 5, 6, 8)
(3, 5, 6, 9)
(3, 5, 6, 0)
(3, 5, 7, 8)
(3, 5, 7, 9)
(3, 5, 7, 0)
(3, 5, 8, 9)
(3, 5, 8, 0)
(3, 5, 9, 0)
(3, 6, 7, 8)
(3, 6, 7, 9)
(3, 6, 7, 0)
(3, 6, 8, 9)
(3, 6, 8, 0)
(3, 6, 9, 0)
(3, 7, 8, 9)
(3, 7, 8, 0)
(3, 7, 9, 0)
(3, 8, 9, 0)
(4, 5, 6, 7)
(4, 5, 6, 8)
(4, 5, 6, 9)
(4, 5, 6, 0)
(4, 5, 7, 8)
(4, 5, 7, 9)
(4, 5, 7, 0)
(4, 5, 8, 9)
(4, 5, 8, 0)
(4, 5, 9, 0)
(4, 6, 7, 8)
(4, 6, 7, 9)
(4, 6, 7, 0)
(4, 6, 8, 9)
(4, 6, 8, 0)
(4, 6, 9, 0)
(4, 7, 8, 9)
(4, 7, 8, 0)
(4, 7, 9, 0)
(4, 8, 9, 0)
(5, 6, 7, 8)
(5, 6, 7, 9)
(5, 6, 7, 0)
(5, 6, 8, 9)
(5, 6, 8, 0)
(5, 6, 9, 0)
(5, 7, 8, 9)
(5, 7, 8, 0)
(5, 7, 9, 0)
(5, 8, 9, 0)
(6, 7, 8, 9)
(6, 7, 8, 0)
(6, 7, 9, 0)
(6, 8, 9, 0)
(7, 8, 9, 0)
Thanks!
Combination is ordered, you can easily see what it produces if you reduce the input:
x = [1,2,3,4]
for c in combinations(x, 2):
print(c)
Output:
(1, 2) (1, 3) (1, 4) # all combinations of 1 and any other number
(2, 3) (2, 4) # (1,2) was already done, so not repeated
(3, 4) # (1,3) and (2,3) already done, so not repeated
You find more details in the documentation.
There is also no reason to do itertools.combinations at all.
Use for c in range(1000,10000): instead. This will create all numbers from 1000 up to 9999
Related
I have this Dataframe that I want to get all possible combinations of this dataframe across both rows and columns.
A_Points
B_Points
C_Points
0
1
1
3
5
4
9
2
4
For example a combination as follows Points = 0 + 5 + 4, or 9 + 1 + 1.
Is there a builtin tool for such problem?
This is what I tried, but it did not give the desired output.
> import itertools
> combined_dataframe = pd.DataFrame({'{}{}'.format(a, b): possible_feature_characteristicpoints[a] - possible_feature_characteristicpoints[b] for a, b in itertools.combinations(possible_feature_characteristicpoints.columns, 2)})
Use itertools.product and sum:
from itertools import product
out = list(map(sum, product(*df.to_numpy().tolist())))
Output:
[12, 5, 7, 14, 7, 9, 13, 6, 8, 13, 6, 8, 15, 8, 10, 14, 7, 9, 13, 6, 8, 15, 8, 10, 14, 7, 9]
Intermediate:
list(product(*df.to_numpy().tolist()))
Output:
[(0, 3, 9),
(0, 3, 2),
(0, 3, 4),
(0, 5, 9),
(0, 5, 2),
(0, 5, 4),
...
(1, 4, 2),
(1, 4, 4)]
Another way with list comprehension,
import pandas as pd
data = {
"A_Points": [0,3,9],
"B_Points": [1,5,2],
"C_Points": [1,4,4],
}
df = pd.DataFrame(data)
result = [ (i, j, k)
for i in df.A_Points
for j in df.B_Points
for k in df.C_Points
]
print(result)
Output:
[(0, 1, 1), (0, 1, 4), (0, 1, 4), (0, 5, 1), (0, 5, 4), (0, 5, 4), (0, 2, 1), (0, 2, 4), (0, 2, 4), (3, 1, 1), (3, 1, 4), (3, 1, 4), (3, 5, 1), (3, 5, 4), (3, 5, 4), (3, 2, 1), (3, 2, 4), (3, 2, 4), (9, 1, 1), (9, 1, 4), (9, 1, 4), (9, 5, 1), (9, 5, 4), (9, 5, 4), (9, 2, 1), (9, 2, 4), (9, 2, 4)]
I am writing some research script in python and I have a list of 9 elements:
a = [1,2,3,4,5,6,7,8,9]
I would like to find all combinations of subsets containing the 3 elements (and NOT the 3 element sets themselves), so for example:
a_new = [ [ [1,2,3],[4,5,6],[7,8,9] ] ],
[ [2,3,4],[5,6,7],[8,9,1] ],
[ [3,4,6],[1,2,8],[5,7,9] ], etc.... ]
the elements are not repeated in the subsets
the sets [3,2,1] and [1,2,3] are the same set and are not unique
Have you perhaps faced such a case, or some Python library will handle it?
Greetings
Use itertools.combinations as follows:
from itertools import combinations
a = {1, 2, 3, 4, 5, 6, 7, 8, 9}
# pick 3
for c_out in combinations(a, r=3):
s_out = set(c_out)
# pick the next 3 from the those elements that are not already picked (i.e not in s_out)
for c_in in combinations(a - s_out, r=3):
# there only 3 elements left so only one way to pick
rest = tuple(a - (s_out | set(c_in)))
print(c_out, c_in, rest)
Output (partial)
(1, 2, 3) (4, 5, 6) (8, 9, 7)
(1, 2, 3) (4, 5, 7) (8, 9, 6)
(1, 2, 3) (4, 5, 8) (9, 6, 7)
(1, 2, 3) (4, 5, 9) (8, 6, 7)
(1, 2, 3) (4, 6, 7) (8, 9, 5)
(1, 2, 3) (4, 6, 8) (9, 5, 7)
(1, 2, 3) (4, 6, 9) (8, 5, 7)
(1, 2, 3) (4, 7, 8) (9, 5, 6)
(1, 2, 3) (4, 7, 9) (8, 5, 6)
(1, 2, 3) (4, 8, 9) (5, 6, 7)
(1, 2, 3) (5, 6, 7) (8, 9, 4)
(1, 2, 3) (5, 6, 8) (9, 4, 7)
(1, 2, 3) (5, 6, 9) (8, 4, 7)
(1, 2, 3) (5, 7, 8) (9, 4, 6)
You can read more about set operations (union, difference) in the documentation.
you can use itertools built-in module
from itertools import combinations
a = [1,2,3,4,5,6,7,8,9]
combination = list(combinations(a, 3))
this output in tuple and you can transform to list easily.
I'm converting some code from Python 2 to Python 3. I have a list of tuples, where each tuple contains a tuple of numbers and a set of numbers. Here's a small example:
l1_python2 = [
((8, 6), Set([1, 2, 3, 4, 5, 6, 7, 8, 9])),
((8, 7), Set([1, 2, 3, 4, 5, 6, 7, 8, 9])),
((0, 3), Set([1, 2, 5, 6, 7, 9])),
((0, 4), Set([1, 2, 5, 6, 7, 9])),
((0, 5), Set([1, 2, 5, 6, 7, 9])),
((0, 6), Set([1, 2, 5, 6, 7, 9])),
((0, 7), Set([1, 2, 5, 6, 7, 9])),
((0, 8), Set([1, 2, 5, 6, 7, 9])),
((1, 0), Set([1, 2, 5, 6, 7, 9])),
((8, 8), Set([1, 2, 3, 4, 5, 6, 7, 8, 9])),
((5, 3), Set([1, 2, 3, 4, 5, 6, 7, 8, 9])),
((5, 4), Set([1, 2, 3, 4, 5, 6, 7, 8, 9])),
((5, 5), Set([1, 2, 3, 4, 5, 6, 7, 8, 9])),
((5, 6), Set([1, 2, 3, 4, 5, 6, 7, 8, 9])),
]
l1_python3 = [
((8, 6), {1, 2, 3, 4, 5, 6, 7, 8, 9}),
((8, 7), {1, 2, 3, 4, 5, 6, 7, 8, 9}),
((0, 3), {1, 2, 5, 6, 7, 9}),
((0, 4), {1, 2, 5, 6, 7, 9}),
((0, 5), {1, 2, 5, 6, 7, 9}),
((0, 6), {1, 2, 5, 6, 7, 9}),
((0, 7), {1, 2, 5, 6, 7, 9}),
((0, 8), {1, 2, 5, 6, 7, 9}),
((1, 0), {1, 2, 5, 6, 7, 9}),
((8, 8), {1, 2, 3, 4, 5, 6, 7, 8, 9}),
((5, 3), {1, 2, 3, 4, 5, 6, 7, 8, 9}),
((5, 4), {1, 2, 3, 4, 5, 6, 7, 8, 9}),
((5, 5), {1, 2, 3, 4, 5, 6, 7, 8, 9}),
((5, 6), {1, 2, 3, 4, 5, 6, 7, 8, 9}),
]
The code to sort in Python 2 is the following:
l1_python2.sort(
lambda a, b: len(a[1]) > len(b[1])
and 1
or len(a[1]) < len(b[1])
and -1
or a[0] > b[0]
and 1
or a[1] < b[1]
and -1
or 0
)
The resulting sorted list is:
[
((0, 3), Set([1, 2, 5, 6, 7, 9])),
((0, 4), Set([1, 2, 5, 6, 7, 9])),
((0, 5), Set([1, 2, 5, 6, 7, 9])),
((0, 6), Set([1, 2, 5, 6, 7, 9])),
((0, 7), Set([1, 2, 5, 6, 7, 9])),
((0, 8), Set([1, 2, 5, 6, 7, 9])),
((1, 0), Set([1, 2, 5, 6, 7, 9])),
((8, 6), Set([1, 2, 3, 4, 5, 6, 7, 8, 9])),
((8, 7), Set([1, 2, 3, 4, 5, 6, 7, 8, 9])),
((8, 8), Set([1, 2, 3, 4, 5, 6, 7, 8, 9])),
((5, 3), Set([1, 2, 3, 4, 5, 6, 7, 8, 9])),
((5, 4), Set([1, 2, 3, 4, 5, 6, 7, 8, 9])),
((5, 5), Set([1, 2, 3, 4, 5, 6, 7, 8, 9])),
((5, 6), Set([1, 2, 3, 4, 5, 6, 7, 8, 9])),
]
I understand (or think that I do) that's it sorting by the length of the sets and by set comparison. I've been trying to convert to Python 3 with no luck though. I tried this first:
l1_python3.sort(
key=(
lambda a, b: len(a[1]) > len(b[1])
and 1
or len(a[1]) < len(b[1])
and -1
or a[0] > b[0]
and 1
or a[1] < b[1]
and -1
or 0
)
)
That gives an error that it's missing one required positional argument b, which makes sense. I then tried this:
l1_python3.sort(
key=(
lambda a: len(a[0][1]) > len(a[1][1])
and 1
or len(a[0][1]) < len(a[1][1])
and -1
or a[0][1] > a[1][1]
and 1
or a[0][1] < a[1][1]
and -1
or 0
)
)
But that returns a TypeError that object of type 'int' has no len(). I've tried a few other things also but they usually don't sort at all. Can anyone help me out?
Thanks!
The weird lambda is actually a convoluted way of saying:
1 if len(a[0][1]) > len(a[1][1])
-1 if len(a[0][1]) < len(a[1][1])
otherwise
1 if a[0][1] > a[1][1]
-1 if a[0][1] < a[1][1]
else 0
So you first want to compare length of elements then theirs values (if length are equals), so your key needs to be something like:
l1_python3.sort(
key=lambda a: (len(a[1]), a[1])
)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I need to create a lot of sets of numbers. I add my output and the output that I need.
I wrote the first item output of my list, then I need the same for all items.
a = [1, 2, 3, 4, 5, 6, 7, 8]
for index, item in enumerate(a):
index_0 = index
index_1 = index + 1
index_2 = index + 2
index_3 = index + 3
print((a[index_0], a[index_1], a[index_2], a[index_3]))
>>>
1, 2, 3, 4
2, 3, 4, 5
3, 4, 5, 6
4, 5, 6, 7
5, 6, 7, 8
What I'm looking for for each item:
1,2,3,4
1,2,3,5
1,2,3,6
1,2,3,7
1,2,3,8
1,2,4,5
1,2,4,6
1,2,4,7
1,2,4,8
1,2,5,6
1,2,5,7
1,2,5,8
1,2,6,7
1,2,6,8
1,2,7,8
1,3,4,5
1,3,4,6
1,3,4,7
1,3,4,8
1,3,5,6
1,3,5,7
1,3,5,8
1,3,6,7
1,3,6,8
1,3,7,8
1,4,5,6
1,4,5,7
1,4,5,8
1,4,6,7
1,4,6,8
1,4,7,8
1,5,6,7
1,5,7,8
1,6,7,8
Are you looking to use itertools combinations:
from itertools import combinations
list(combinations([1,2,3,4,5,6,7,8], 4))
Output:
[(1, 2, 3, 4),
(1, 2, 3, 5),
(1, 2, 3, 6),
(1, 2, 3, 7),
(1, 2, 3, 8),
(1, 2, 4, 5),
(1, 2, 4, 6),
(1, 2, 4, 7),
(1, 2, 4, 8),
(1, 2, 5, 6),
(1, 2, 5, 7),
(1, 2, 5, 8),
(1, 2, 6, 7),
(1, 2, 6, 8),
(1, 2, 7, 8),
(1, 3, 4, 5),
(1, 3, 4, 6),
(1, 3, 4, 7),
(1, 3, 4, 8),
(1, 3, 5, 6),
(1, 3, 5, 7),
(1, 3, 5, 8),
(1, 3, 6, 7),
(1, 3, 6, 8),
(1, 3, 7, 8),
(1, 4, 5, 6),
(1, 4, 5, 7),
(1, 4, 5, 8),
(1, 4, 6, 7),
(1, 4, 6, 8),
(1, 4, 7, 8),
(1, 5, 6, 7),
(1, 5, 6, 8),
(1, 5, 7, 8),
(1, 6, 7, 8),
(2, 3, 4, 5),
(2, 3, 4, 6),
(2, 3, 4, 7),
(2, 3, 4, 8),
(2, 3, 5, 6),
(2, 3, 5, 7),
(2, 3, 5, 8),
(2, 3, 6, 7),
(2, 3, 6, 8),
(2, 3, 7, 8),
(2, 4, 5, 6),
(2, 4, 5, 7),
(2, 4, 5, 8),
(2, 4, 6, 7),
(2, 4, 6, 8),
(2, 4, 7, 8),
(2, 5, 6, 7),
(2, 5, 6, 8),
(2, 5, 7, 8),
(2, 6, 7, 8),
(3, 4, 5, 6),
(3, 4, 5, 7),
(3, 4, 5, 8),
(3, 4, 6, 7),
(3, 4, 6, 8),
(3, 4, 7, 8),
(3, 5, 6, 7),
(3, 5, 6, 8),
(3, 5, 7, 8),
(3, 6, 7, 8),
(4, 5, 6, 7),
(4, 5, 6, 8),
(4, 5, 7, 8),
(4, 6, 7, 8),
(5, 6, 7, 8)]
I'm having trouble unpacking a 2-dimensional list of tuples (or rather, I'm looking for a more elegant solution).
The list is as shown:
a = [ [(2, 3, 5), (3, 4, 6), (4, 5, 7), (1, 1, 1), (1, 2, 3)],
[(4, 9, 2), (8, 8, 0), (3, 5, 1), (2, 6, 8), (2, 4, 8)],
[(8, 7, 5), (2, 5, 1), (9, 2, 2), (4, 5, 1), (0, 1, 9)], ...]
And I want to unpack the tuples to obtain 3 nested lists of the same form, i.e.:
a_r = [ [2, 3, 4, 1, 1] , [4, 8, 3, 2, 2] , [8, 2, 9, 4, 0] , ...]
a_g = [ [3, 4, 5, 1, 2] , [9, 8, 5, 6, 4] , [7, 5, 2, 5, 1] , ...]
and so on. Here is my code:
a_r = []
a_g = []
a_b = []
for i in xrange(len(a)):
r0=[]
g0=[]
b0=[]
for j in range(5):
r0.append(a[i][j][0])
g0.append(a[i][j][1])
b0.append(a[i][j][2])
a_r.append(r0)
a_g.append(g0)
a_b.append(b0)
I'm sure there are more efficient ways to do this (I've just begun learning Python). This question is similar, but I wasn't able to follow the functional programming.
Thanks!
I think you are after something like this:
a = [ [(2, 3, 5), (3, 4, 6), (4, 5, 7), (1, 1, 1), (1, 2, 3)],
[(4, 9, 2), (8, 8, 0), (3, 5, 1), (2, 6, 8), (2, 4, 8)],
[(8, 7, 5), (2, 5, 1), (9, 2, 2), (4, 5, 1), (0, 1, 9)]]
for row in a:
print(list(zip(*row)))
Which gives:
[(2, 3, 4, 1, 1), (3, 4, 5, 1, 2), (5, 6, 7, 1, 3)]
[(4, 8, 3, 2, 2), (9, 8, 5, 6, 4), (2, 0, 1, 8, 8)]
[(8, 2, 9, 4, 0), (7, 5, 2, 5, 1), (5, 1, 2, 1, 9)]
The resulting tuples are same as in your example, but different order. I dont understand how you ordered them. If you could clarify this, I might modify the example.
Hope this helps.
>>> a = [ [(2, 3, 5), (3, 4, 6), (4, 5, 7), (1, 1, 1), (1, 2, 3)],
... [(4, 9, 2), (8, 8, 0), (3, 5, 1), (2, 6, 8), (2, 4, 8)],
... [(8, 7, 5), (2, 5, 1), (9, 2, 2), (4, 5, 1), (0, 1, 9)]]
>>> zip(*(zip(*x) for x in a))
[((2, 3, 4, 1, 1), (4, 8, 3, 2, 2), (8, 2, 9, 4, 0)), ((3, 4, 5, 1, 2), (9, 8, 5, 6, 4), (7, 5, 2, 5, 1)), ((5, 6, 7, 1, 3), (2, 0, 1, 8, 8), (5, 1, 2, 1, 9))]
>>> for row in _:
... print row
...
((2, 3, 4, 1, 1), (4, 8, 3, 2, 2), (8, 2, 9, 4, 0))
((3, 4, 5, 1, 2), (9, 8, 5, 6, 4), (7, 5, 2, 5, 1))
((5, 6, 7, 1, 3), (2, 0, 1, 8, 8), (5, 1, 2, 1, 9))
If it must be lists
>>> map(list, zip(*(map(list, zip(*x)) for x in a)))
[[[2, 3, 4, 1, 1], [4, 8, 3, 2, 2], [8, 2, 9, 4, 0]], [[3, 4, 5, 1, 2], [9, 8, 5, 6, 4], [7, 5, 2, 5, 1]], [[5, 6, 7, 1, 3], [2, 0, 1, 8, 8], [5, 1, 2, 1, 9]]]
>>> for row in _:
... print row
...
[[2, 3, 4, 1, 1], [4, 8, 3, 2, 2], [8, 2, 9, 4, 0]]
[[3, 4, 5, 1, 2], [9, 8, 5, 6, 4], [7, 5, 2, 5, 1]]
[[5, 6, 7, 1, 3], [2, 0, 1, 8, 8], [5, 1, 2, 1, 9]]
Tuples are immutable (meaning you cannot change them), so you're going to have to go through every element to extract them. That is essentially what the functional programming example you linked to is doing, in a very pythonic, list comprehension, way.
To help you help yourself, as shirdharama says, take a look at the example again and know that fmap_lol really means "function mapping - list of lists", fmap_list means "function mapping - list", and fmap_el means "function mapping - element". So split_nt calls fmap_lol, which splits your input in a list of lists (the tuples), calls fmap_list, which takes each list and calls fmap_el, which returns the element back up the chain.
The example is just a way to walk through the tuples to extract every element and put them where you wish. It's functional because they are functions calls, not a single line of later forgotten gobbligook.
If you're unfamiliar with list comprehensions, lamda (or anonymous functions), or anything else in the example I suggest spending some time with the python documentation and looking each up.