July 2018

Python: How to pass arguments as a list to a function that takes a variable number of arguments

Some functions take in their parameters a variable number of arguments *args, for example, the itertools.product function.

In order to pass the list as the parameters to this function, we need to use the * operator:

 

Python: How to convert a string with mixed numbers and ranges of numbers to a list

Conversion of a string with both individual numbers and ranges of numbers to the list of integer values can be made as follows:

For example a line:

Split the line by comma delimiter:

Let’s split the resulting list into two lists. In the first list, we put only the individual values. In the second – the values got from the ranges of numbers.

Combine the lists into one and drop the duplicate values.

Complete code:

 

PHP: How to get the full class name with static inheritance

PHP supports the Late Static Bindings mechanism. The full class name with static inheritance we can get by calling the function:

Example: