Tutorial by Examples: o

A shallow copy is a copy of a collection without performing a copy of its elements. >>> import copy >>> c = [[1,2]] >>> d = copy.copy(c) >>> c is d False >>> c[0] is d[0] True
If you have nested lists, it is desireable to clone the nested lists as well. This action is called deep copy. >>> import copy >>> c = [[1,2]] >>> d = copy.deepcopy(c) >>> c is d False >>> c[0] is d[0] False
You can create shallow copies of lists using slices. >>> l1 = [1,2,3] >>> l2 = l1[:] # Perform the shallow copy. >>> l2 [1,2,3] >>> l1 is l2 False
A dictionary object has the method copy. It performs a shallow copy of the dictionary. >>> d1 = {1:[]} >>> d2 = d1.copy() >>> d1 is d2 False >>> d1[1] is d2[1] True
Sets also have a copymethod. You can use this method to perform a shallow copy. >>> s1 = {()} >>> s2 = s1.copy() >>> s1 is s2 False >>> s2.add(3) >>> s1 {[]} >>> s2 {3,[]}
In functional programming languages like F# null values are considered potentially harmful and poor style (non-idiomatic). Consider this C# code: string x = SomeFunction (); int l = x.Length; x.Length will throw if x is null let's add protection: string x = SomeFunction (); int l = x ...
Error handling is important but can make an elegant algorithm into a mess. Railway Oriented Programming (ROP) is used to make error handling elegant and composable. Consider the simple function f: let tryParse s = let b, v = System.Int32.TryParse s if b then Some v else None let f (g : ...
MATCH (n) WHERE n.some_attribute = "some identifier" SET n.other_attribute = "a new value"
Box Collider A primitive Collider shaped like a cuboid. Properties Is Trigger - If ticked, the Box Collider will ignore physics and become a Trigger Collider Material - A reference, if specified, to the physics material of the Box Collider Center - The Box Collider's central posit...
I create a file called database-servlet.xml somewhere on the classpath. Initially your config file will look like this: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/...
One of the great things about Linq is that it is so easy to extend. You just need to create an extension method whose argument is IEnumerable<T>. public namespace MyNamespace { public static class LinqExtensions { public static IEnumerable<List<T>> Batch<T&...
To print a user-readable error message to stderr, call perror from <stdio.h>. int main(int argc, char *argv[]) { FILE *fout; if ((fout = fopen(argv[1], "w")) == NULL) { perror("fopen: Could not open file for writing"); return EXIT_FAILURE; } r...
The @each directive allows you to iterate through any list or map. It takes the form of @each $var or <list or map> {} where $var can be any variable name and <list or map> can be anything that returns a list or map. In the following example, the loop will iterate through the $authors l...
One of the easiest examples of using shared services is when we want to store some data from a given page of our application, and then get that data again but from another page. One option could be to send that data as a parameter (for instance, if one page calls the other one) but if we want to us...
The following sqoop command will be used to import the data from RDBMS table into HBase table, if the table does not exists in HBase it will create a new table and import the data into this table sqoop import \ --query 'select emp_id, emp_name, emp_sal from employee where $CONDITIONS' \ ...
UITextView has extra paddings by default. Sometimes it's annoying especially if you want to measure some text without view instance and place them at some area precisely. Do this to remove such paddings. messageTextView.textContainerInset = UIEdgeInsetsZero messageTextView.textContainer.lineFragm...

For

For-loops iterate over an iterating collection. An iterating collection is any class which structurally unifies with Iterator<T> or Iterable<T> types from the Haxe standard library. A for-loop which logs numbers in range 0 to 10 (exclusive) can be written as follows: for (i in 0...10) ...
Do-while-loops execute a body expression at least once, and then keep executing it as long as the loop condition evaluates to true. A do-while-loop which logs numbers in range 10 to 0 (inclusive) can be written as follows: var i = 10; do { trace(i); } while (i-- > 0); Try the example ...
The flow or execution of a loop can be controlled by use of break and continue expressions. Break break exits the current loop. In case the loop is nested inside another loop, the parent loop is unaffected. for (i in 0...10) { for (j in 0...10) { if (j == 5) break; trace(i,...
Before starting you must have: Anaconda installed on your system Account on Binstar If you are not using Anaconda 1.6+ install the binstar command line client: $ conda install binstar $ conda update binstar If you are not using Anaconda the Binstar is also available on pypi: $ pip install bin...

Page 452 of 1038