Bottom Page

• 3 Vote(s) - 3 Average
• 1
• 2
• 3
• 4
• 5
 Converting List of 3 Element Tuple to Dictionary fooikonomou Programmer named Tim Posts: 5 Threads: 1 Joined: Jan 2019 Reputation: 0 Likes received: 0 #11 Jan-11-2019, 09:17 PM (Jan-11-2019, 04:27 PM)DeaD_EyE Wrote: result = [] for element in data:     sorted_tuple = sorted(element)     result.append(sorted_tuple) print(result) It worked Many thanks!!! perfringo Splitter Posts: 188 Threads: 1 Joined: Jun 2018 Reputation: 12 Likes received: 45 #12 Jan-14-2019, 09:51 AM Based on DeaD_EyE code we can build one-liner list comprehension that sorts both elements and list: ```>>> data = [(1, 5, 1), (1, 3, 2), (1, 3, 1), (1, 1, 4)] >>> sorted([tuple(sorted(element)) for element in data]) [(1, 1, 3), (1, 1, 4), (1, 1, 5), (1, 2, 3)] ``` I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy « Next Oldest | Next Newest »

Top Page

 Possibly Related Threads... Thread Author Replies Views Last Post Tuple Unpacking HarshaliPatel 2 51 Yesterday, 02:40 PM Last Post: buran Using xpath to get value of a nested element name using tag named xq1xq1xq1 3 74 Jan-18-2019, 07:13 PM Last Post: Larz60+ converting the items of a list in new lists clarablanes 2 78 Jan-13-2019, 12:54 PM Last Post: clarablanes Python Selenium getting table element trengan 2 129 Dec-31-2018, 03:02 PM Last Post: trengan Click Element if displayed using Selenium and Python giaco__mar 1 108 Dec-27-2018, 06:19 PM Last Post: metulburr Need help with weird tuple syntax mwskz8 2 93 Dec-13-2018, 09:58 AM Last Post: buran Converting Angle to X and Y Values: 90/180/270 deg qrani 1 153 Nov-21-2018, 06:41 PM Last Post: woooee Replace element in a nested list nagymusic 4 223 Nov-19-2018, 08:03 PM Last Post: nilamo AttributeError: 'tuple' object has no attribute 'interface' Kim6071 0 163 Nov-18-2018, 03:06 PM Last Post: Kim6071 dictionary: print key/value with list(dict) comprehension wardancer84 4 194 Nov-14-2018, 03:14 PM Last Post: wardancer84

Forum Jump:

Users browsing this thread: 1 Guest(s)