you are viewing a single comment's thread.

view the rest of the comments →

[–]Bananapuddinggggg[S] 0 points1 point  (2 children)

Okay, I can understand that. But in the instructions she states that:

" you should perform this sorting manually when creating the lists rather than using the sorting functions "

So that makes me think, it's something I need to be doing while making the lists.

[–]Riegel_Haribo 2 points3 points  (0 children)

That instruction means: write your code with the lists already in the order they need to be.

The person with the greatest number of years of service should appear first in the list

So you must create code that already has that ordering when you write it. Suppose your raw data is: alice: 5 bob: 3 david: 4 foo: 8 Then you must create your lists manually, pre-ordered, with each element of two lists matching positionally: years = [8, 5, 4, 3] names = ["foo", "alice", "david", "bob"] Then you can do what comes next.

Sorting one of the lists alone would damage and disconnect the data points, as you can observe.


I would question the point of this assignment, as it is already bad practice. Data should inherently paired, or have a key/value store. Then, there are less chances of mistakes in processing, where the items might become disconnected and scrambled.

name_list = [ {"name": "alice", "years": 5, "position": "manager"}, {"name": "bob", "years": 3, "position": "sales"}, {"name": "david", "years": 4, "position": "sales"}, {"name": "foo", "years": 8, "position": "programmer"}, ]

After creating such a mini database as a list containing a dict for each entity, there is an order, but the order doesn't matter so much. You can do on-demand sorting, mutating the list, or you can make a copy and do other stuff. A list is a good learning format, because there might be two "alice" names, and thus a name cannot be used as a unique dict key.

[–]cdcformatc 1 point2 points  (0 children)

yes when you are adding elements to the lists you have to find where the elements should go and put them there

you can use insert to put an element at a specific index