How to Find the Largest and Smallest Element in a list in Python

Photo by Giu Vicente on Unsplash

One of the first algorithms that we are usually taught is finding either the smallest or the largest element in a list of elements by iterating through every element in a list.

Let’s assume that we are trying to find the smallest element in a list.

The algorithm is quite straightforward and intuitive even for a 5-year-old: You assume that the first element is the smallest and save its value in a variable.

You then keep on comparing this value with all the elements in the list from the first one until the last one checking whether there is another…

Photo by Peter Gombos on Unsplash

It’s inevitable that you need to work with lists in your day-to-day job.

A list of users. A list of store items. A list of objects. A one potentially rare task that you may need to do is get a random element in a list.

There can be many ways that you can use to do that, but in this article, I am going to share 2 ways that can hopefully be helpful.

1. Using random.randint()

You have probably used methods from the random library already, trying to get a randomized numerical value that you may need to do some initializations, or adding…

Photo by Manik Roy on Unsplash

In one way or another, you are probably constantly using lists in your day-to-day job.

This means that you may at least need to find their sum which is part of a task.

You probably know a sort-of universal way of finding the sum of elements in a list is pretty much all programming languages out there:

Iterate through a list of elements and then keep on adding the value of that element to a variable in which you have initialized before the start of the iteration.

In other words, it is just a general algorithm that resembles the way…

Image source

When you see famous developers in the industry, you tend to think highly of them.

Somehow you think that you are the only person who is facing job rejections.

They are always able to get whichever job they want, and it was always like that. When we take a closer look, it cannot be further from the truth.

1. Remind yourself that you are not the only one

First of all, it can happen to anyone. There can be coding challenges that you may not be able to solve at the time of the interview due to stress, or that you made a mistake, or forgot something as you haven’t…

Mistake #3 — Trying to master everything in a single night

Child thinking — pensively
Child thinking — pensively
Photo by Johnny Cohen on Unsplash

We see many articles about tips on how to become a successful software developer.

Habits you should start to adapt. Mindset shifts you need to make. Advice that you should follow.

However, there is not that much emphasis on things that we need to avoid. Mistakes and time wasters that could cause a lot of harm in our life. A lot of frustration and disappointment that we are not achieving anything.

That’s what you are about to read in this article.

Let’s get started…

1. Memorizing Every Possible Detail of the Syntax

You move to a new city, and you don’t know where the nearest grocery store is…

These can help you if you are having a hard time understanding Machine Learning papers

Photo by Dan Dimmock on Unsplash

With the new quick advancements of machine learning and AI in general, we are witness to an increasing challenge of keeping up with the pace as the field processes at a faster rate than we may be able to keep up with.

Add to this the fact that a new paper is usually built on top of other previously published work and they may not give you the details about it which you then also need to go and read for that particular paper.

This chain of papers that you need to look up to and understand before you understand…

34. Strings and tuples are immutable

Photo by Jexo on Unsplash

Python is quite popular nowadays, mainly due to its simplicity, and easiness to learn.

You can use it for a wide range of tasks like data science and machine learning, web development, scripting, automation, etc.

Since this is a pretty long article and you want to reach its end before you finish your coffee, why don’t we just start?

Okay, here we go…

1. “Else” condition inside a “for” loop

Despite all the Python code that you have seen so far, chances are that you may have missed the following “for-else” which I also got to see for the first time a couple of weeks ago.


Photo by Brad Neathery on Unsplash

If you use Python in your work, or simply for scripting, chances are that there will come a point in time when you are going to need to work with dates.

It can be doing a conversion from one format to the other one, changing the timezone, etc.

Since you have already decided to read this article, then why don’t we stop wasting time talking and just start immediately learning?

1. Convert a string into a date

Despite being engineers, we still spend a considerable amount of time using a natural language to talk.

Since that is the case, we can also convert a string looking like…

How industry titans have contextualized and dealt with failure

SpaceX founder Elon Musk.
SpaceX founder Elon Musk.
Elon Musk

When you get rejected from a job, you get the impression that you are a failure, the only person who didn’t manage to get that, that you are doomed.

You beat yourself up.

However, if you look at the data, it is hard to find someone who never failed, or was never rejected.

In this category, we include people who also currently amaze us with the work that they have done.

Elon Musk, Founder of Paypal, Tesla, Space X

Elon Musk is one of the most popular people on this list, as being one of the most ambitious and hard-working people, who aims to make humanity an interplanetary…

Photo by Haddad Azfa on Unsplash

A software bug in a Therac-25 radiation therapy machine caused the death of five patients after receiving a massive dose of X-rays.

Knight Capital lost half a billion dollars in half an hour when a software bug allowed computers to sell and buy millions of shares with no human oversight.

These and many other stories tell how seemingly unimportant bugs can actually cause so many tragic disasters.

Fatos Morina

Machine Learning Engineer | Let us connect on LinkedIn:

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store