Re: Sorting a multidimensional array by multiple keys



Rehceb Rotkiv <rehceb@xxxxxxxxxxx> wrote:

Wait, I made a mistake. The correct result would be

reaction is BUT by the
pattern , BUT it is
rapid , BUT it is
sea , BUT it is
sodium , BUT it is
this manner BUT the dissolved

because "by the" comes before and "the dissolved" after "it is". Sorry
for the confusion.

data = [
"reaction is BUT by the",
"sodium , BUT it is",
"sea , BUT it is",
"this manner BUT the dissolved",
"pattern , BUT it is",
"rapid , BUT it is",
]
data = [ s.split() for s in data]
from pprint import pprint
pprint(data)
[['reaction', 'is', 'BUT', 'by', 'the'],
['sodium', ',', 'BUT', 'it', 'is'],
['sea', ',', 'BUT', 'it', 'is'],
['this', 'manner', 'BUT', 'the', 'dissolved'],
['pattern', ',', 'BUT', 'it', 'is'],
['rapid', ',', 'BUT', 'it', 'is']]
from operator import itemgetter
data.sort(key=itemgetter(0))
data.sort(key=itemgetter(1))
data.sort(key=itemgetter(4))
data.sort(key=itemgetter(3))
pprint(data)
[['reaction', 'is', 'BUT', 'by', 'the'],
['pattern', ',', 'BUT', 'it', 'is'],
['rapid', ',', 'BUT', 'it', 'is'],
['sea', ',', 'BUT', 'it', 'is'],
['sodium', ',', 'BUT', 'it', 'is'],
['this', 'manner', 'BUT', 'the', 'dissolved']]
.



Relevant Pages

  • Re: Sorting a multidimensional array by multiple keys
    ... sodium, BUT it is ... sea, BUT it is ... this manner BUT the dissolved ... pattern, BUT it is ...
    (comp.lang.python)
  • Re: Sorting a multidimensional array by multiple keys
    ... reaction is BUT by the ... pattern, BUT it is ... rapid, BUT it is ... sea, BUT it is ...
    (comp.lang.python)
  • Re: Sorting a multidimensional array by multiple keys
    ... reaction is BUT by the ... sodium, BUT it is ... sea, BUT it is ... this manner BUT the dissolved ...
    (comp.lang.python)
  • Re: Apidra
    ... ob ich mit dem gleichen Faktor wie bei Insuman Rapid beginnen sollte oder lieber vorsichtiger und niedriger dosieren sollte? ... ich dachte das solch eine Fragestellung automatisch vom Diabetologen beantwortet wird. ... Bei der Umstellung unserer Tochter von Actrapid auf Novorapid hat sich der BE-Faktor nicht geändert. ...
    (de.sci.medizin.diabetes)
  • Re: If lightspeed were constant to all frames
    ... The new light source is not sodium although its pattern can be used to ... although its pattern can be used to determine that the original source ...
    (sci.physics.relativity)