Tutorial by Examples: ar

pattern = r"(your base)" sentence = "All your base are belong to us." match = re.search(pattern, sentence) match.group(1) # Out: 'your base' match = re.search(r"(belong.*)", sentence) match.group(1) # Out: 'belong to us.' Searching is done anywhere in the ...
Special characters (like the character class brackets [ and ] below) are not matched literally: match = re.search(r'[b]', 'a[b]c') match.group() # Out: 'b' By escaping the special characters, they can be matched literally: match = re.search(r'\[b\]', 'a[b]c') match.group() # Out: '[b]' T...
MATLAB allows for several methods to index (access) elements of matrices and arrays: Subscript indexing - where you specify the position of the elements you want in each dimension of the matrix separately. Linear indexing - where the matrix is treated as a vector, no matter its dimensions. That ...
Available in the standard library as defaultdict from collections import defaultdict d = defaultdict(int) d['key'] # 0 d['key'] = 5 d['key'] # 5 d = defaultdict(lambda: 'empty') d['key'] # 'empty' d['key'] = 'full' ...
To create a variable in Python, all you need to do is specify the variable name, and then assign a value to it. <variable name> = <value> Python uses = to assign values to variables. There's no need to declare a variable in advance (or to assign a data type to it), assigning a value ...
4.0 To uppercase $ v="hello" # Just the first character $ printf '%s\n' "${v^}" Hello # All characters $ printf '%s\n' "${v^^}" HELLO # Alternative $ v="hello world" $ declare -u string="$v" $ echo "$string" HELLO WORLD To l...
The following example shows common AngularJS constructs in one file: <!DOCTYPE html> <html ng-app="myDemoApp"> <head> <style>.started { background: gold; }</style> <script src="https://code.angularjs.org/1.5.8/angular.min.js">&lt...
Given this data: dateamount2016-03-122002016-03-11-502016-03-141002016-03-151002016-03-10-250 SELECT date, amount, SUM(amount) OVER (ORDER BY date ASC) AS running FROM operations ORDER BY date ASC will give you dateamountrunning2016-03-10-250-2502016-03-11-50-3002016-03-12200-1002016-03-1410...
3.0 Check if a string consists in exactly 8 digits: $ date=20150624 $ [[ $date =~ ^[0-9]{8}$ ]] && echo "yes" || echo "no" yes $ date=hello $ [[ $date =~ ^[0-9]{8}$ ]] && echo "yes" || echo "no" no
git log -S"#define SAMPLES" Searches for addition or removal of specific string or the string matching provided REGEXP. In this case we're looking for addition/removal of the string #define SAMPLES. For example: +#define SAMPLES 100000 or -#define SAMPLES 100000 git log -G&q...
To delete a remote branch in Git: git push [remote-name] --delete [branch-name] or git push [remote-name] :[branch-name]
Evaluates its first operand, and, if the resulting value is not equal to zero, evaluates its second operand. Otherwise, it evaluates its third operand, as shown in the following example: a = b ? c : d; is equivalent to: if (b) a = c; else a = d; This pseudo-code represents it : c...
In order to get const char* access to the data of a std::string you can use the string's c_str() member function. Keep in mind that the pointer is only valid as long as the std::string object is within scope and remains unchanged, that means that only const methods may be called on the object. C++1...
Can be used to shorten if/else operations. This comes in handy for returning a value quickly (i.e. in order to assign it to another variable). For example: var animal = 'kitty'; var result = (animal === 'kitty') ? 'cute' : 'still nice'; In this case, result gets the 'cute' value, because the v...
Generally To use regular expression specific characters (?+| etc.) in their literal meaning they need to be escaped. In common regular expression this is done by a backslash \. However, as it has a special meaning in Java Strings, you have to use a double backslash \\. These two examples will not ...
A CLOS class is described by: a name a list of superclasses a list of slots further options like documentation Each slot has: a name an initialization form (optional) an initialization argument (optional) a type (optional) a documentation string (optional) accessor, reader and/or wr...
Go is a statically typed language, meaning you generally have to declare the type of the variables you are using. // Basic variable declaration. Declares a variable of type specified on the right. // The variable is initialized to the zero value of the respective type. var x int var s string va...
In Go, you can declare multiple variables at the same time. // You can declare multiple variables of the same type in one line var a, b, c string var d, e string = "Hello", "world!" // You can also use short declaration to assign multiple variables x, y, z := 1, 2, 3 ...
Pointer addition Given a pointer and a scalar type N, evaluates into a pointer to the Nth element of the pointed-to type that directly succeeds the pointed-to object in memory. int arr[] = {1, 2, 3, 4, 5}; printf("*(arr + 3) = %i\n", *(arr + 3)); /* Outputs "4", arr's fourth e...
The X-macro approach can be generalized a bit by making the name of the "X" macro an argument of the master macro. This has the advantages of helping to avoid macro name collisions and of allowing use of a general-purpose macro as the "X" macro. As always with X macros, the mas...

Page 15 of 218