Tutorial by Examples: comp

The filter or map functions should often be replaced by list comprehensions. Guido Van Rossum describes this well in an open letter in 2005: filter(P, S) is almost always written clearer as [x for x in S if P(x)], and this has the huge advantage that the most common usages involve predicates tha...
The module cmath includes additional functions to use complex numbers. import cmath This module can calculate the phase of a complex number, in radians: z = 2+3j # A complex number cmath.phase(z) # 0.982793723247329 It allows the conversion between the cartesian (rectangular) and polar repr...
Python has built-in support for complex arithmetic. The imaginary unit is denoted by j: z = 2+3j # A complex number w = 1-7j # Another complex number Complex numbers can be summed, subtracted, multiplied, divided and exponentiated: z + w # (3-4j) z - w # (1+10j) z * w # (23-11j) z / w # (...
Long vectors with long runs of the same value can be significantly compressed by storing them in their run-length encoding (the value of each run and the number of times that value is repeated). As an example, consider a vector of length 10 million with a huge number of 1's and only a small number o...
A React component can be defined as an ES6 class that extends the base React.Component class. In its minimal form, a component must define a render method that specifies how the component renders to the DOM. The render method returns React nodes, which can be defined using JSX syntax as HTML-like ta...
The for clause of a list comprehension can specify more than one variable: [x + y for x, y in [(1, 2), (3, 4), (5, 6)]] # Out: [3, 7, 11] [x + y for x, y in zip([1, 3, 5], [2, 4, 6])] # Out: [3, 7, 11] This is just like regular for loops: for x, y in [(1,2), (3,4), (5,6)]: print(x+y) ...
Two std::strings can be compared lexicographically using the operators ==, !=, <, <=, >, and >=: std::string str1 = "Foo"; std::string str2 = "Bar"; assert(!(str1 < str2)); assert(str > str2); assert(!(str1 <= str2)); assert(str1 >= str2); assert...
Given the following HTML file: index.html <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>React Tutorial</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.2.1/react.js"></script>...
Composer tracks which versions of packages you have installed in a file called composer.lock, which is intended to be committed to version control, so that when the project is cloned in the future, simply running composer install will download and install all the project's dependencies. Composer de...
A lot of the power of ReactJS is its ability to allow nesting of components. Take the following two components: var React = require('react'); var createReactClass = require('create-react-class'); var CommentList = reactCreateClass({ render: function() { return ( <div className...
Following the Rcpp example in this documentation entry, consider the following tough-to-vectorize function, which creates a vector of length len where the first element is specified (first) and each element x_i is equal to cos(x_{i-1} + 1): repeatedCosPlusOne <- function(first, len) { x <-...
You can create widgets composed of multiple widgets using MultiWidget. from datetime import date from django.forms.widgets import MultiWidget, Select from django.utils.dates import MONTHS class SelectMonthDateWidget(MultiWidget): """This widget allows the user to fill in ...
This assumes that you have read the documentation about starting a new Django project. Let us assume that the main app in your project is named td (short for test driven). To create your first test, create a file named test_view.py and copy paste the following content into it. from django.test impo...
If you have a f :: Lens' a b and a g :: Lens' b c then f . g is a Lens' a c gotten by following f first and then g. Notably: Lenses compose as functions (really they just are functions) If you think of the view functionality of Lens, it seems like data flows "left to right"—this might ...
What’s a component? A component is basically a directive that uses a simpler configuration and that is suitable for a component-based architecture, which is what Angular 2 is all about. Think of a component as a widget: A piece of HTML code that you can reuse in several different places in y...
iex(1)> recompile Compiling 1 file (.ex) :ok
For instance, a computation involving commands to read and write from the prompt: First we describe the "commands" of our computation as a Functor data type {-# LANGUAGE DeriveFunctor #-} data TeletypeF next = PrintLine String next | ReadLine (String -> next) derivin...
JavaScript has four different equality comparison operations. SameValue It returns true if both operands belong to the same Type and are the same value. Note: the value of an object is a reference. You can use this comparison algorithm via Object.is (ECMAScript 6). Examples: Object.is(1, 1); ...
After the C pre-processor has included all the header files and expanded all macros, the compiler can compile the program. It does this by turning the C source code into an object code file, which is a file ending in .o which contains the binary version of the source code. Object code is not directl...
You can set the opacity to a certain UIColor without creating a new one using the init(red:_,green:_,blue:_,alpha:_) initializer. Swift let colorWithAlpha = UIColor.redColor().colorWithAlphaComponent(0.1) Swift 3 //In Swift Latest Version _ colorWithAlpha = UIColor.red.withAlphaComponent(0.1)...

Page 4 of 34