Software engineering and personal development

Tag: machine learning (Page 1 of 2)

How to Quickly Split a String on the First N Occurrences in Python

brown wooden blocks on white surface
Photo by Brett Jordan on Unsplash

You have probably seen cases when you can do splits of strings into multiple parts based on a pattern that is observed in the string. For example, let us say that we want to save all the words that are part of a sentence. 

To do that, we usually try to do split the sentence into words based on the spaces that we find, such as:

Continue reading

How to Quickly Find the Symmetric Difference of 2 Sets in Python

low-angle photography of brown concrete building during daytime
Photo by Samuel-Elias Nadler on Unsplash

If you have to find the union of elements that are either in the first or the second set, but not in both of them, then you need to use the symmetric difference.

This is also another math operation between sets that you have probably seen in a math class in high school.

This can be done quite easily and quickly using 2 built-in methods in Python.

Let’s start with the first one.

Continue reading

How to Assign Multiple Variables in a Single Line in Python

assorted-color mugs on rack
Photo by Eric Prouzet on Unsplash

One of the first things that you learn when you start to program is learning how to declare a variable and assign to it a value.

For example, you are told to assign a string and then print it in a console:

Now, if we want to assign another variable in there, our intuition can be to just add a new line, and assign it there:

Continue reading

How to Remove the First and Last Element of a List in Python

yellow leaves near green leaves
Photo by Ryan Song on Unsplash

Lists represent one of the most used data structures in any Python script. One of the reasons why I like programming in Python is that I get to reach a result quite quickly.

One such thing is the opportunity to easily and quite simply access their elements quite flexibly.

With flexibility, I mean, having the opportunity to choose only the elements that we want.

Continue reading
« Older posts

© 2024 Fatos Morina

Theme by Anders NorenUp ↑