0

I have a string list and a float list, they both print vertically using a For Loop.

**PS. The outputs are meant to be vertical,not horizontal. I don't know why it's shown that way, probably because I'm new to this platform.

Current Output:

for i in range(0,5,1):
    print(string[I], float[i], "s")

Output:

String1 20 s
String2 40 s
String3 10 s
String4 60 s
String5 80 s

My Objective: I want to sort them by the numbers in ascending order.

Objective:

Output:

String3 10 s
String1 20 s
String2 40 s
String4 60 s
String5 80 s

Trial and Error Attempts:

I tried to use the .sort() function. However, it sorts the numbers but the names don't correspond to the numbers that were originally assigned to them.

I want the numbers and strings to be joined together and sort them both by only using the numbers (float) in ascending order.

ggorlen
  • 44,755
  • 7
  • 76
  • 106
Cloud
  • 1
  • 1
  • 1
    `string[I]` and `float[i]` is invalid python. and you don't even have an `I` variable in your example. please review – Jab Dec 01 '22 at 14:57
  • you could try using a dictionary, and assigning the string and float to a key of the float – Hunter Dec 01 '22 at 14:58
  • @Cloud please don't undo edits that were made to clear up your formatting. I already fixed the problem you mentioned in your edit. Use triple backticks to make code blocks in markdown (not specific to SO). – ggorlen Dec 01 '22 at 14:58

0 Answers0