My last post I had used a data structure to handle the words and their counts, but sorting that structure was messy. I played around with a few songs from a few major artists and bands, and found their song was typically between 374 and 601 words long. The few I dove deeper into generally had roughly 114+ unique words. What that means is that in an absolutely worst case scenario a single run could have 114 moves in a single array or 228 total moves between both arrays. Thankfully, there is a way to keep the data structure I created and significantly reduce the amount of moves at every step. Instead of trying to sort both arrays based on the value of one array, it is very possible to create class objects in Python.
Full transparency, this idea came to me when someone criticized my background in Python and mentioned the C programming language. Python’s spot on the programming hierarchy means it can resemble both C and C++, though C style code tends to be more straightforward. One of the primary strengths of C++ is that you can create custom containers that can group attributes together as a single object. This let me iterate through whichever array I wanted, get related values from both arrays simultaneously in order, and associate them with a single object. The result is that I was able to use a built-in search method for Python lists, give it an anonymous function (lambda), tell it to sort by value, and the end result was exactly what I was after with very little effort.
Lastly. even though it is an unpopular opinion I will die on the hill that a programming language’s place in the hierarchy does not just tell us about its performance. No one is impressed by C-Style C++ code, and poorly written C or C++ code will be slower or more dangerous than a quick Python or Java app any day. I only write my applications in Python because it’s a lot quicker and safe. Plus I can switch up the design of the application on the fly to fit my needs.
Lastly, you can find the script, a demo video, and article about it all here. You may have seen the post before this publishes because I simply updated the old page for sake of simplicity.
If you make a purchase at Amazon using the link below I may receive commission from your purchase.
Tech Best Sellers at Amazon