Tutorial by Examples: ear

You can extend the functionality of existing yield methods by passing in one or more values or elements that could define a terminating condition within the function by calling a yield break to stop the inner loop from executing. public static IEnumerable<int> CountUntilAny(int start, HashSet...
The LinearLayout is a ViewGroup that arranges its children in a single column or a single row. The orientation can be set by calling the method setOrientation() or using the xml attribute android:orientation. Vertical orientation : android:orientation="vertical" <?xml version=&quo...
Map<Integer, String> map = new HashMap<>(); map.put(1, "First element."); map.put(2, "Second element."); map.put(3, "Third element."); map.clear(); System.out.println(map.size()); // => 0
The Java language provides 7 operators that perform arithmetic on integer and floating point values. There are two + operators: The binary addition operator adds one number to another one. (There is also a binary + operator that performs string concatenation. That is described in a separate e...
The git clone command is used to copy an existing Git repository from a server to the local machine. For example, to clone a GitHub project: cd <path where you'd like the clone to create a directory> git clone https://github.com/username/projectname.git To clone a BitBucket project: cd ...
Arrays of strings can be created using ruby's percent string syntax: array = %w(one two three four) This is functionally equivalent to defining the array as: array = ['one', 'two', 'three', 'four'] Instead of %w() you may use other matching pairs of delimiters: %w{...}, %w[...] or %w<...&...
2.0 array = %i(one two three four) Creates the array [:one, :two, :three, :four]. Instead of %i(...), you may use %i{...} or %i[...] or %i!...! Additionally, if you want to use interpolation, you can do this with %I. 2.0 a = 'hello' b = 'goodbye' array_one = %I(#{a} #{b} world) array_tw...
An empty Array ([]) can be created with Array's class method, Array::new: Array.new To set the length of the array, pass a numerical argument: Array.new 3 #=> [nil, nil, nil] There are two ways to populate an array with default values: Pass an immutable value as second argument. P...
One can give a function as many arguments as one wants, the only fixed rules are that each argument name must be unique and that optional arguments must be after the not-optional ones: def func(value1, value2, optionalvalue=10): return '{0} {1} {2}'.format(value1, value2, optionalvalue1) Wh...
There is a problem when using optional arguments with a mutable default type (described in Defining a function with optional arguments), which can potentially lead to unexpected behaviour. Explanation This problem arises because a function's default arguments are initialised once, at the point whe...
One method is available for counting the number of occurrences of a sub-string in another string, str.count. str.count(sub[, start[, end]]) str.count returns an int indicating the number of non-overlapping occurrences of the sub-string sub in another string. The optional arguments start and end ...
Sometimes it's necessary to set an array to zero, after the initialization has been done. #include <stdlib.h> /* for EXIT_SUCCESS */ #define ARRLEN (10) int main(void) { int array[ARRLEN]; /* Allocated but not initialised, as not defined static or global. */ size_t i; for(i ...
You can list existing git aliases using --get-regexp: $ git config --get-regexp '^alias\.' Searching aliases To search aliases, add the following to your .gitconfig under [alias]: aliases = !git config --list | grep ^alias\\. | cut -c 7- | grep -Ei --color \"$1\" "#" The...
All built-in collections in Python implement a way to check element membership using in. List alist = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 5 in alist # True 10 in alist # False Tuple atuple = ('0', '1', '2', '3', '4') 4 in atuple # False '4' in atuple # True String astring = 'i am a s...
dict have no builtin method for searching a value or key because dictionaries are unordered. You can create a function that gets the key (or keys) for a specified value: def getKeysForValue(dictionary, value): foundkeys = [] for keys in dictionary: if dictionary[key] == value: ...
Searching in nested sequences like a list of tuple requires an approach like searching the keys for values in dict but needs customized functions. The index of the outermost sequence if the value was found in the sequence: def outer_index(nested_sequence, value): return next(index for index, ...
To clear the storage, simply run localStorage.clear();
The searched CASE returns results when a boolean expression is TRUE. (This differs from the simple case, which can only check for equivalency with an input.) SELECT Id, ItemId, Price, CASE WHEN Price < 10 THEN 'CHEAP' WHEN Price < 20 THEN 'AFFORDABLE' ELSE 'EXPENSIVE' E...
To allow the use of in for custom classes the class must either provide the magic method __contains__ or, failing that, an __iter__-method. Suppose you have a class containing a list of lists: class ListList: def __init__(self, value): self.value = value # Create a set of al...
Dates don't exist in isolation. It is common that you will need to find the amount of time between dates or determine what the date will be tomorrow. This can be accomplished using timedelta objects import datetime today = datetime.date.today() print('Today:', today) yesterday = today - date...

Page 1 of 21