Tutorial by Examples: f

Removing a variable name from the scope using del v, or removing an object from a collection using del v[item] or del[i:j], or removing an attribute using del v.name, or any other way of removing references to an object, does not trigger any destructor calls or any memory being freed in and of itsel...
This example creates a new file named "NewFile.txt", then writes "Hello World!" to its body. If the file already exists, CreateFile will fail and no data will be written. See the dwCreationDisposition parameter in the CreateFile documentation if you don't want the function to fa...
Using the timeit module from the command line: > python -m timeit 'for x in xrange(50000): b = x**3' 10 loops, best of 3: 51.2 msec per loop > python -m timeit 'from math import pow' 'for x in xrange(50000): b = pow(x,3)' 100 loops, best of 3: 9.15 msec per loop The built-in ** operato...
To get basic information about a DataFrame including the column names and datatypes: import pandas as pd df = pd.DataFrame({'integers': [1, 2, 3], 'floats': [1.5, 2.5, 3], 'text': ['a', 'b', 'c'], 'ints with None': [1, None, 3]}) ...
df = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6], 'c': [7, 8, 9]}) To list the column names in a DataFrame: >>> list(df) ['a', 'b', 'c'] This list comprehension method is especially useful when using the debugger: >>> [c for c in df] ['a', 'b', 'c'] This is the long w...
// MARK: - UICollectionViewDelegateFlowLayout extension ViewController: UICollectionViewDelegateFlowLayout { func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize { return ...
You can use an initializer to set default property values: struct Example { var upvotes: Int init() { upvotes = 42 } } let myExample = Example() // call the initializer print(myExample.upvotes) // prints: 42 Or, specify default property values as a part of the property...
This is a minimalist module that only slurps files into variables, nothing else. use File::Slurper 'read_text'; my $contents = read_text($filename); read_text() takes two optional parameters to specify the file encoding and whether line endings should be translated between the unixish LF or DOS...
Don't use it. Although it has been around for a long time and is still the module most programmers will suggest, it is broken and not likely to be fixed.
Examine the following strings: foobarfoo bar foobar barfoo the regular expression bar will match all four strings, \bbar\b will only match the 2nd, bar\b will be able to match the 2nd and 3rd strings, and \bbar will match the 2nd and 4th strings.
A recursive function is simply a function, that would call itself. function factorial (n) { if (n <= 1) { return 1; } return n * factorial(n - 1); } The above function shows a basic example of how to perform a recursive function to return a factorial. Another...
import locale locale.setlocale(locale.LC_ALL, '') Out[2]: 'English_United States.1252' locale.currency(762559748.49) Out[3]: '$762559748.49' locale.currency(762559748.49, grouping=True) Out[4]: '$762,559,748.49'
First of all, we need to add our first Fragment at the beginning, we should do it in the onCreate() method of our Activity: if (null == savedInstanceState) { getSupportFragmentManager().beginTransaction() .addToBackStack("fragmentA") .replace(R.id.container, FragmentA.n...
So let's suppose you want to iterate only between some specific lines of a file You can make use of itertools for that import itertools with open('myfile.txt', 'r') as f: for line in itertools.islice(f, 12, 30): # do something here This will read through the lines 13 to 20 as i...
You can use flatMap(_:) in a similar manner to map(_:) in order to create an array by applying a transform to a sequence's elements. extension SequenceType { public func flatMap<T>(@noescape transform: (Self.Generator.Element) throws -> T?) rethrows -> [T] } The difference with...
sed -i s/"what to replace"/"with what to replace"/g $file We use -i to select in-place editing on the $file file. In some systems it is required to add suffix after -i flag which will be used to create backup of original file. You can add empty string like -i '' to omit the b...
ansible -i hosts -m ping targethost -i hosts defines the path to inventory file targethost is the name of the host in the hosts file
Flask has a utility called jsonify() that makes it more convenient to return JSON responses from flask import Flask, jsonify app = Flask(__name__) @app.route('/api/get-json') def hello(): return jsonify(hello='world') # Returns HTTP Response with {"hello": "world"} ...
If the mimetype of the HTTP request is application/json, calling request.get_json() will return the parsed JSON data (otherwise it returns None) from flask import Flask, jsonify app = Flask(__name__) @app.route('/api/echo-json', methods=['GET', 'POST', 'DELETE', 'PUT']) ...
public void iterateAndFilter() throws IOException { Path dir = Paths.get("C:/foo/bar"); PathMatcher imageFileMatcher = FileSystems.getDefault().getPathMatcher( "regex:.*(?i:jpg|jpeg|png|gif|bmp|jpe|jfif)"); try (Direc...

Page 69 of 457