Sort a deeply nested tuple
iteration, python, python-3.x, tuples
Solution
Something like the following - using a list comp to build new tuples...
l = [('apple', ['gala','fuji', 'macintosh']),
('pear', ['seckel','anjou','bosc'])]
l2 = [(k, sorted(v)) for k, v in l]
# [('apple', ['fuji', 'gala', 'macintosh']), ('pear', ['anjou', 'bosc', 'seckel'])]
Problem
I have a list of nested tuples that looks like: ``` l = [('apple', ['gala','fuji', 'macintosh']), ('pear', ['seckel','anjou','bosc'])] ``` And I like to sort the second item of the tuple alphabetically, so that it would look like: ``` l2 = [('apple', ['fuji','gala', 'macintosh']), ('pear', ['anjou','bosc','seckel'])] ``` I know that I could apply `sorted(l)` to it, but I am very new to Python and I am having problems with the iteration. How can I do that?