Python Forum
Help With Parallel Arrays
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help With Parallel Arrays
#4
Since your month stay the same and are unique you could think of using a dictionary.
A different approach could be to have a third list. Lets consider that monthList are your month and rainAmount is your rain amount. Let us make a new list amount_indices containing [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] which are the indices of your rainAmount. Now you sort your list and therefore configure the indices in your amount_indices, after that you have a mapping from your indices of your amount_indices to the values stored in amount_indices.
A slightly different approach would be if you sort both list parallel while changing the index of an element in rainAmount you change the index of the corresponding month. so just change this little part of your code to:
for i in range(0, len(rainAmount) - 1):
    for j in range(0, len(rainAmount) - 1 - i):
        if rainAmount[j] > rainAmount[j+1]:
            rainAmount[j], rainAmount[j+1] = rainAmount[j+1], rainAmount[j]
            monthList[j], monthList[j+1] = monthList[j+1], monthList[j]
Reply


Messages In This Thread
Help With Parallel Arrays - by toxicxarrow - May-02-2018, 07:20 AM
RE: Help With Parallel Arrays - by buran - May-02-2018, 07:49 AM
RE: Help With Parallel Arrays - by toxicxarrow - May-02-2018, 08:01 AM
RE: Help With Parallel Arrays - by ThiefOfTime - May-02-2018, 08:01 AM
RE: Help With Parallel Arrays - by killerrex - May-02-2018, 08:13 AM
RE: Help With Parallel Arrays - by toxicxarrow - May-02-2018, 08:15 AM
RE: Help With Parallel Arrays - by buran - May-02-2018, 11:03 AM
RE: Help With Parallel Arrays - by toxicxarrow - May-02-2018, 10:06 PM
RE: Help With Parallel Arrays - by snippsat - May-02-2018, 11:42 PM
RE: Help With Parallel Arrays - by toxicxarrow - May-03-2018, 11:47 PM
RE: Help With Parallel Arrays - by snippsat - May-04-2018, 02:54 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020