In Python, there are 2 ways to delete a character from a string.
Using replace Method
The str.replace(old, new[, count]) method returns a copy of the string with all occurrences of substring old replaced by new. If the optional argument count is giv...
In Python, there are 2 ways to extract all the numbers contained in a string.
Using List Comprehension
List comprehensions provide a concise way to create lists.
If you only want to extract only positive integers, try the following:
#!/usr/bin/...
In PHP, there are 2 ways to check if a string contains a specific word.
Using strpos Function
The strpos(string $haystack, string $needle, int $offset = 0): int|false function finds the numeric position of the first occurrence of needle in the hayst...
In Python, there are 3 ways to get the position of a character.
Using find Method
The str.find(sub[, start[, end]]) method returns the lowest index in the string where substring sub is found within the slice s[start:end]. Optional arguments start an...
In Python, there are 2 ways to find out the number of CPUs.
Using multiprocessing Module
The multiprocessing.cpu_count() method returns the number of CPUs in the system. For example,
#!/usr/bin/python3
# Import module
import multiprocessing
c...
In Python, there are 3 ways to get key by value in dictionary.
Using keys Function
Basically, it separates the dictionary's values in a list, finds the position of the value you have, and gets the key at that position.
The following example:
#!...
In Golang, using the NumCPU function is the easiest way to find out the number of CPU's on a local machine.
Using runtime.NumCPU Function
The runtime.NumCPU() method returns the number of logical CPUs usable by the current process.
The set of avail...
In Golang, using the a case-insensitive flag is the easiest way to do a case insensitive regular expression.
Using a case-insensitive flag
You can set a case-insensitive flag as the first item in the regex.
You can add a (?i) at the beginning of th...
In Rust, using the position function is the easiest way to find the index of an element in a vector.
Using position Method
The position() method searches for an element in an iterator, returning its index.
position() is short-circuiting; in other ...
In Python, there are 3 ways to list all files of a directory.
Using os.listdir Method
Return a list containing the names of the entries in the directory given by path. The list is in arbitrary order, and does not include the special entries '.' and ...
In Golang, there are 3 ways to remove packages installed with go get.
Using go mod tidy
go mod tidy ensures that the go.mod file matches the source code in the module. It adds any missing module requirements necessary to build the current module’s p...
In Golang, there are 2 ways to read a file line-by-line.
Using bufio.Scanner Function
Scanner provides a convenient interface for reading data such as a file of newline-delimited lines of text. The ones that are currently implemented are:
packa...
In Python, there are 4 ways to find the intersection between two lists.
Using Set Intersection
A set is an unordered collection with no duplicate elements. Basic uses include membership testing and eliminating duplicate entries. Set objects also sup...
In Python, there are 5 ways to find the difference between two lists.
Using Set Difference
A set is an unordered collection with no duplicate elements. Basic uses include membership testing and eliminating duplicate entries. Set objects also support...
In Rust, there are 3 ways to check if string contains substring.Using String contains Function
The easiest way to check if a Rust string contains a substring is to use String::contains method.
The contains method Returns true if the given pattern m...