In Python, there are 3 ways to remove all empty strings from a list of strings.
Using filter Function
The filter(function, iterable) function constructs an iterator from those elements of iterable for which function returns true.
The following exam...
In Python, using the str.join function is the easiest way to concatenate a list of strings into a single string
Using str.join Function
The str.join() method returns a string which is the concatenation of the strings in iterable. A TypeError will be...
In Python, there are 3 ways to return dictionary keys as a list.
Using keys Function
The dict.keys() function returns a view object that displays a list of all the keys in the dictionary in order of insertion.
See the following example:
#!/usr/...
In Python, there are 2 ways to determine if an object is iterable.
Using Duck Typing
Duck typing is a concept related to dynamic typing, where the type or the class of an object is less important than the methods it defines. When you use duck typing...
In Python, there are 3 ways to remove duplicates in list.
Using Built-in set Function
The built-in set() function returns a new set object, optionally with elements taken from iterable. If you later need a real list again, you can similarly pass the...
In Rust, there are 2 ways to convert Vec to a string.
Using collect Function
The collect() function transforms an iterator into a collection. collect() can take anything iterable, and turn it into a relevant collection. This is one of the more powe...
In Python, there are 4 ways to know if an object has an attribute.
Using hasattr Method
The arguments are an object and a string. The result is True if the string is the name of one of the object’s attributes, False if not. For example,
#!/usr/...