python


How to reverse “reversed” duplicated tuples from a list in Python


Suppose I have a list of tuples:
a = [(a,b), (a,b), (b,c), (b,a), (a,b), (c,b)]
How can I find all the 'reversed' duplicated tuples like (a,b) and (b,a), (b,c) and (c,b); and change elements inside tuples in a consistent order, so it can become:
a = [(a,b), (a,b), (b,c), (a,b), (a,b), (b,c)]
Short answer
Convert tuples to list, sort the list, return it to a tuple type.
def sort_tuples(alistoftuples):
return [tuple(sorted(list(k))) for k in alistoftuples]

Related Links

In matplotlib, what's the difference between title() and suptitle()?
Modifying and rewriting .csv files in Python
How do I scroll to a certain widget in a QScrollArea
NoSuchKey when getting a signed url for a cloudstorage object with a space in the name
Not sure how to parse this
Error drawing 3D graph in python
How to change objects in a python script by using a keyboardinterrupt for specific keys?
Arguments to an object's parent's function
python regex ignoring underscore incorrectly
Will installing Anaconda3 change Mac OS X default Python version to 3.4?
Devices Labels. Python Code Debugging
Adding list of values to rows, turning the dataframe into long format afterwards
bottle_mysql Encoding failure
What exactly does the {'page': 1} mean here? “BuildError: ('main.user_profile', {'page': 1}, None)”
Saving the results as LUT
Python 2.7 : Pytz : ImportError: cannot import name timezone

Categories

HOME
converter
sidekiq
redis
jsviews
decorator
zend-framework2
ios10
data-science-experience
proguard
sudo
lotus-notes
metronic
image-recognition
store
typeahead
uicollectionview
bar-chart
multiple-columns
avplayeritem
servicemix
jquery-scrollify
npm-install
searchbar
logarithm
fabric
bus-error
xilinx-ise
cell-array
svnkit
oracle-xml-db
hashcat
vsts-package-management
rhel.net
codesys
discord.net
mongoexport
silverlight-3.0
fltk
twiki
rule
cgo
android-maps-v2
html-agility-pack
cppunit
apiary
context-free-language
gd
rhel6
rollback
udev
rpostgresql
visual-studio-templates
excon
tuxedo
gemini
concur
asynccallback
aerogear
sun-codemodel
throughput
unity5.3
textkit
visual-studio-code
calibration
pyopengl
digits
mdm-zinc
stackframe
uptodate
orientation-changes
cocoascript
libsndfile
grunt-contrib-concat
getimagedata
mfmailcomposeviewcontroll
alertifyjs
lumx
roxygen
chrome-for-android
dynamic-proxy
magicalrecord-2.2
loop-invariant
image-zoom
vmware-server
pep8
fileconveyor
qt4.6
fieldset
dynamic-data
marmalade-edk
autostart
deploying
gjs
concurrent-programming
entity-framework-ctp5
msgbox
mysql-error-1045
datamember
curljs
pantheios
carbide
pci-bus
openvg
openwysiwyg
handheld

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App