Skip to main content

Posts

Showing posts with the label python lists

what is a ragged and jagged array?

Introduction: I go through different things people comes searching to my website and recently I found out this new term named ragged and jagged list. I wasn't familiar with the term, so I read about it and going to talk about it from different language and usage perspectives in this article. So by the end of this article, you should be a master of the concept called "ragged or jagged array". Definition: A ragged array, also called jagged array, ( yes they are two same things), is basically a non-uniform array, which consists of different length lists as elements. For example, [[1],[1,2,3],[2,5]] is a jagged array. The name arises from the concept that if you list the elements down one by one vertically, then the edge will be ragged/jagged. How to create: In python, it can be quite simple to create. You can just take an empty list []; and then keep pushing different lists one by one using append. For getting a better idea, read about python lists . For java, read it f...

Climbing the leaderboard: a simple yet elegant problem

                                           Introduction:                                       Photo by Ethan Johnson on Unsplash I have recently embarked upon the journey of getting a few stars in my cap by starting small-time coding in hackerrank. While I am only a 3-star noob there yet, I really liked one problem which I solved today. So in this post, we will discuss the solution and speed optimizations I had to implement to solve the problem. The problem description: The problem is climbing the leaderboard . The problem statement is simple. There is a leaderboard, where dense ranking metho...

python3 list: creation, addition, deletion

 Introduction: Lists are one of the most fundamental data structures in python3.  In this article we are going to go through the basics and some of the advanced usage of lists in python and where should you use them and where you should not use them. what is list? List is a python data structure which is equivalent to a dynamic array in C++ or C. List is used to store normally homogeneous elements in python3; but pythons allow to store dissimilar elements in a list too. To say in summary, list is an ordered linear data structure. How to create a list? List can be created by using as simple as writing list = []; which initiates an empty list. Also, there is the list() builtin function in python which also creates a list. Empty lists can be created using both [] and list(); but it is known that [] is a bit faster method to initiate an empty list.  List can also be created with the elements to be put into it. i.e. you can start a list with the elements it is supposed t...