Introduction In this Python code snippet post, we are going to implement a list reverse function from the scratch without using any builtin functions. Let us see how… Iterative solution We can use a for loop to swap the first and last items, the second and the one before the last item and so on
Problem Given an input string, provide Python code to remove all special characters except spaces. Solution This is a typical regular expressions question. Please find the answer below.. Code The idea is to match only letters, spaces and exclude everything else. Take a look… That is for today. Thanks for visiting. Questions ? Please use
Introduction In Python, the datetime module can be used to get date and time. This is good but there is something annoying: the milliseconds or the fraction that gets printed by default. How can we get rid of that ? There are a couple of ways to do the trick. Let us see… Example code
Introduction If you skim through Python source code, you may encounter some strings proceeded by a special character such as (b, u). What are these characters? Let us see… The b string prefix The b string prefix in Python 3.x indicates that the string is of type byte stream. If the prefix is not used,
Introduction I think the reason why this topic can be confusing specially to beginners is that it mixes different concepts together. It should not be hard to understand with proper context. In my opinion, to better understand the difference between Args and Kwargs in Python, the following points must be crystal clear… Positional vs keyword
Introduction For more information about for loops in Python, you can find the full article here. So what is the difference between break, continue and pass in Python ? let us borrow some relevant sections from the previous article… Break statement Python like other languages provides a special purpose statement called break. This statement terminates
Introduction In this tiny Python code snippet article, I am going to borrow from the full article about the topic that you can find here. So, what is the difference between bytes and bytearray in Python ? There is no real difference between byte strings and byte arrays except the fact that byte strings are
Introduction So you are curious to know the key difference between a list and tuple in Python ? You can find the answer in many places on the web, however in this code snippet we will summarize it so that it is easy to remember. Take a look at the following table… List vs Tuple
Introduction Welcome to a new Python code snippets post. Below, you can find a summary of helpful Python syntax for that purpose… Let us now take some examples… Sorted dictionary keys This will print… Sorted dictionary values This will print… Sorted dictionary items by value This will print… Sorting in reverse order This will print…
Introduction Comparing strings is a very common task in coding. How do we do that in Java ? well there are tons of content in that regard. I compiled the bare minimum that you need in case you are only looking for the syntax. Take a look… Syntax Summary Let us demonstrate that… Source code