1

I just required some help with my Python code which I am trying to create. This sorts a '2D Array' which contains both Numbers and Letters (Alphanumeric) to be sorted Numerically. So I have the below Array:

Array = (['Apple',1],['Banana',8],['Grape',120],['Pineapple',80])

And I was looking for an output which would sort numerically highest - lowest, for example I need the below output or similar:

(['Grape',120],['Pineapple',80],['Banana',8],['Apple',1])

Or something like this

Grape, 120
Pineapple, 80
Banana, 8
Apple, 1
styvane
  • 59,869
  • 19
  • 150
  • 156
DW_0505
  • 99
  • 1
  • 7

1 Answers1

1

Use the built in sorted operation:

sorted(Array, key=lambda x: x[1], reverse=True)
dlshriver
  • 156
  • 1
  • 15