Guided Project 2: sorted swap sorting partially

Hi there,

I just finished the hacker news guided project but I have encountered a problem in my code. My sorted_swap list sorted the average comments per post per hour partially and by that I mean it sorted (9.41-5.58) and then (38.59-10.09). I have done this project in a separate jupyter notebook with the full dataset and encountered the same issue. Can anybody help me with this code please?

I have attached both notebooks here:
Basics.ipynb (11.7 KB)
Hacker News Analysis.ipynb (11.3 KB)

Click here to view the jupyter notebook file in a new tab

The values at index 0 are strings, so when you sort them, it’s using lexicographic order (the same kind of order you find in the dictionary).

This means that, for instance, 5 is greater than 1000000000000, because:

  • 5 starts with 5;
  • 1000000000000 starts with 1; and
  • 5 is lexicographically greater than 1.

In your example, the following chain o inequalities is true: 9>8>7>6>5>4>3>2>1.

I hope this helps.

Oh that makes a lot of sense. My mistake was formatting the average number of comments before sorting. Thanks a lot.

1 Like