Home » 2020 » November

How to Get the Length of a List in Python

How to get the length of a list in Python

This tutorial will teach you how to find the length of a list (array) in Python using some code examples. There are four data structures built into Python: tuples, sets, dictionaries, and lists. They are important for programmers because they allow for iteration over their contents. When we talk about data structures such as lists in Python, we are referring to a collection data type. Lists in Python can be ordered and changed. Also, unlike the sets collection type, a list allows for duplicated entries, … Read more

Home » 2020 » November

How to Reverse a List in Python

How to Reverse a List in Python

Even outside of programming, people perform list reversal regularly, for example, to re-order eBay items from high to low then low to high. It is a handy operation, and Python provides several ways to accomplish it. Method 1: Using the built-in reverse() function This method has the advantage of being simple and easy to understand when using someone else’s code. For example, if we have stored our list in “staffNames”: staffNames = [“Abigail”, “Chris”, “Denise”, “Fred”] staffNames.reverse() When executed, this method doesn’t automatically give a … Read more

Home » 2020 » November

FAQ: How to disable/remap a keyboard key in Linux?

disable remap a keyboard key in Linux

Q: How can I disable one or several keys on my laptop keyboard in Linux? When I press the DELETE key, it gets stuck and deletes everything 🙂

A: No problem! You can use the following command to remap or disable any key of your keyboard:

xmodmap -e 'keycode <value>=<action>'

For example, you could run the following command to disable your DELETE key:

xmodmap -e 'keycode 107='

How to get the correct keycode

You can get the keycode that corresponds to a specific keyboard button in one of two ways.

The first method is by using the simple command xev. xev opens a window and then monitors “events” such as keystrokes. It is suitable when you are running a GUI.

xev

The second method, which can be run with only the console, is showkey. This command will monitor for keystrokes for 10 seconds, or until a SIGTERM signal is received.

List of all keycodes

The full list of available keycodes and actions assigned to them on UK keyboard is below…

Read more

Home » 2020 » November

PHP ‘str_replace’ Function: Find and Replace Text

php str_replace function

The PHP str_replace() function replaces words or sections (known as substrings) in a string with other words or sentences, allowing you to modify or reformat text values (find and replace text). Syntax str_replace ( $search , $replace , $subject [, &$count ] ) Note that: $search is the string value being searched for – it can even be an array of strings if you wish to search for multiple values $replace is the value you wish to replace the $search value with – it can also be an array if … Read more

Categories PHP

Home » 2020 » November

Using the PHP ‘explode’ Function (With Examples)

php explode function

PHP is one of the most popular programming languages used to develop web applications and APIs. Linux is the system of choice for serving up your PHP code and is also an ideal PHP development environment. The PHP explode function is vital for processing user input. It takes a string (a series of characters) and splits it up into smaller strings by a given delimiter to specify the boundary of where the splits should occur. Syntax explode ( $delimiter , $string [, $limit ] ) Note that: $delimiter … Read more

Categories PHP

Home » 2020 » November

Using the PHP ‘substr’ Function (With Examples)

Using the PHP 'substr' Function

PHP is one of the most popular programming languages used to develop web applications and APIs. Linux is the system of choice for serving up your PHP code and is also an ideal PHP development environment. The PHP substr function takes a string (a series of characters) and returns only the specified portion of it. Syntax substr ( $string , $start [, $length ] ) Note that: The function returns either the specified portion of the given $string (even if it’s empty) as a new string … Read more

Categories PHP

Home » 2020 » November

How to Install Ubuntu MATE 2020.10 on a Raspberry Pi (With Screenshots)

How to Install Ubuntu MATE 2020.10 on a Raspberry Pi

Ubuntu is (arguably) the most popular Linux distribution. Ubuntu MATE is a great, performance-conscious, lightweight Ubuntu-based distribution that is perfect for low-cost platforms like the Raspberry Pi where you may want to forgo some of the bells and whistles for better performance. If you’re just getting started learning Linux and programming you may not want to risk trying things out on your day-to-day computer (you might be worried about breaking it for work or school), a Raspberry Pi is a great way to experiment with … Read more

Home » 2020 » November

Python Find in List: Check if an Element is Present

python find in list

Python offers several different types of arrays for storing data. Lists are arrays which allow you to store items. These list items can be altered, and are stored in a specific order. There are several methods you should consider for searching a list in Python– searching for a specific value match, or searching for list items that match a certain condition or set of conditions. You can also remove items from a list in Python. Checking if a List Contains an Item Using the ‘in’ … Read more

Home » 2020 » November

Concatenating (Joining) Strings in Python

string concatenation python

Let’s look at two ways you can concatenate (which is a fancy word for join or merge) two or more strings in Python. It’s also worth checking out our article on converting integers to strings in Python. A Note On Immutable Strings Strings in Python are immutable and cannot be changed once defined. This means that whenever you join two strings, a new string is created (ie. the original is not modified!). This has both performance side effects and affects how you should structure your code: … Read more

Home » 2020 » November

ls Command in Linux to List Files and Directories

ls Command in Linux

The ls command in Linux is likely one of the first commands you ever need to use. In this article, we’ll go over the command and commonly used parameters. My preferred set of options is as follows: ls -Zaltrh Let’s dig into each option individually, and explain why the entire glob of options is helpful. Linux LS Command Syntax #ls [OPTION] [FILE] OPTIONS: [-a], do not ignore entries starting with . or .. [-h], with -l, print sizes in human readable format (e.g., 1K 234M … Read more