All Go Rust Python PHP JavaScript
Chrome Dev Summit to secure your spot in workshops, office hours and learning lounges!

How to Delete a Character from a String in Python

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...
Unused

How to Extract All the Numbers Contained in a String in Python

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/...
Sambhav Khandelwal

How to check if a string contains a specific word in PHP

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...
ada

How to Get the Psition of a Character in Python

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...
aweis

How to Find Out the Number of CPUs in Python

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...
Sambhav Khandelwal

How to Get Key by Value in Dictionary in Python

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: #!...
aweis

How to Find Out the Number of CPU's on a Local Machine in Go

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...
Tomoki

How to Do a Case Insensitive Regular Expression in Go

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...
ada

How to Find the Index of an Element in a Vector in Rust

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 ...
pooriabt

How to List All Files of a Directory in Python

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 ...
ada

How to Remove Packages Installed with go get in Go

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...
ada

How to Read a File Line-by-Line in Go

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...
Sambhav Khandelwal

How to find the intersection between two lists in Python

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...
Unused

How to find the difference between two lists in Python

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...
Sambhav Khandelwal

How to check if string contains substring in Rust

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...
Tomoki