Skip to main content

Python - Learning - Important point - p3

List Functions
-list.append(x)
-list.extend(L)
-list.insert(i, x)
-list.remove(x)
-list.pop([i])
-list.clear()
-list.index(x)
-list.count(x)
-list.sort(key=None, reverse=False)
-list.reverse()
-list.copy()

It is also possible to use a list as a queue, where the first element added is the first element retrieved (“first-in, first-out”); however, lists are not efficient for this purpose. While appends and pops from the end of list are fast, doing inserts or pops from the beginning of a list is slow (because all of the other elements have to be shifted by one).

To implement a queue, use collections.deque which was designed to have fast appends and pops from both ends.
There is a way to remove an item from a list given its index instead of its value: the del statement. This differs from the pop() method which returns a value. The del statement can also be used to remove slices from a list or clear the entire list (which we did earlier by assignment of an empty list to the slice). 

Tuple

We saw that lists and strings have many common properties, such as indexing and slicing operations. They are two examples of sequence data types (see Sequence Types — list, tuple, range). Since Python is an evolving language, other sequence data types may be added. There is also another standard sequence data type: the tuple.
A tuple consists of a number of values separated by commas,


Output tuples are always enclosed in parentheses, so that nested tuples are interpreted correctly; they may be input with or without surrounding parentheses, although often parentheses are necessary anyway (if the tuple is part of a larger expression). It is not possible to assign to the individual items of a tuple, however it is possible to create tuples which contain mutable objects.Though tuples may seem similar to lists, they are often used in different situations and for different purposes. Tuples are immutable, and usually contain a heterogeneous sequence of elements that are accessed via unpacking (see later in this section) or indexing (or even by attribute in the case of namedtuples). Lists are mutable, and their elements are usually homogeneous and are accessed by iterating over the list.
A special problem is the construction of tuples containing 0 or 1 items: the syntax has some extra quirks to accommodate these. Empty tuples are constructed by an empty pair of parentheses; a tuple with one item is constructed by following a value with a comma (it is not sufficient to enclose a single value in parentheses). Ugly, but effective.

Sets
A set is an unordered collection with no duplicate elements. Basic uses include membership testing and eliminating duplicate entries. Set objects also support mathematical operations like union, intersection, difference, and symmetric difference.
Curly braces or the set() function can be used to create sets. Note: to create an empty set you have to use set(), not {}; the latter creates an empty dictionary, a data structure that we discuss in the next section.


Dictionaries
It is best to think of a dictionary as an unordered set of key: value pairs, with the requirement that the keys are unique (within one dictionary). A pair of braces creates an empty dictionary: {}. Placing a comma-separated list of key:value pairs within the braces adds initial key:value pairs to the dictionary; this is also the way dictionaries are written on output.
The main operations on a dictionary are storing a value with some key and extracting the value given the key. It is also possible to delete a key:value pair with del. If you store using a key that is already in use, the old value associated with that key is forgotten. It is an error to extract a value using a non-existent key.
Performing list(d.keys()) on a dictionary returns a list of all the keys used in the dictionary, in arbitrary order (if you want it sorted, just usesorted(d.keys()) instead). [2] To check whether a single key is in the dictionary, use the in keyword.
The dict() constructor builds dictionaries directly from sequences of key-value pairs.


Conditions

The conditions used in while and if statements can contain any operators, not just comparisons.
The comparison operators in and not in check whether a value occurs (does not occur) in a sequence. The operators is and is not compare whether two objects are really the same object; this only matters for mutable objects like lists. All comparison operators have the same priority, which is lower than that of all numerical operators.
Comparisons can be chained. For example, a < b == c tests whether a is less than b and moreover b equals c.
Comparisons may be combined using the Boolean operators and and or, and the outcome of a comparison (or of any other Boolean expression) may be negated with not. These have lower priorities than comparison operators; between them, not has the highest priority and or the lowest, so that Aand not B or C is equivalent to (A and (not B)) or C. As always, parentheses can be used to express the desired composition.
The Boolean operators and and or are so-called short-circuit operators: their arguments are evaluated from left to right, and evaluation stops as soon as the outcome is determined. For example, if A and C are true but B is false, A and B and C does not evaluate the expression C. When used as a general value and not as a Boolean, the return value of a short-circuit operator is the last evaluated argument.

Comments

Popular posts from this blog

Installing OpenERP on Ubuntu 12.04

1. Install Ubuntu Server with OpenSSH Server.So that you can run your commands from a remote server. 2. Run the following commands to install required depedency sudo apt-get install postgresql postgresql-client python-dateutil python-feedparser python-gdata python-ldap python-libxslt1 python-lxml python-mako python-openid python-psycopg2 python-pybabel python-pychart python-pydot python-pyparsing python-reportlab python-simplejson python-tz python-vatnumber python-vobject python-webdav python-werkzeug python-xlwt python-yaml python-zsi 3. Download Latest Openerp all file wget http://nightly.openerp.com/6.1/releases/openerp_6.1-1-1_all.deb 4. Install openErp server. sudo dpkg -i openerp_6.1-1-1_all.deb sudo apt-get install openerp -f 5. Reboot 6. Access the Web Client using http://ip:8069

20 Extensions for VSCode For Node+Angular2 Development

Here is the list of Extensions which I found important and Interesting. The names are in the form of  Author.Name christian-kohler.npm-intellisense CoenraadS.bracket-pair-colorizer DavidAnson.vscode-markdownlint dbaeumer.jshint donjayamanne.githistory ecmel.vscode-html-css eg2.tslint eg2.vscode-npm-script fknop.vscode-npm formulahendry.auto-close-tag formulahendry.auto-rename-tag HookyQR.beautify humao.rest-client lonefy.vscode-JS-CSS-HTML-formatter mkaufman.HTMLHint msjsdiag.debugger-for-chrome prashaantt.node-tdd rbbit.typescript-hero robertohuertasm.vscode-icons Zignd.html-css-class-completion See the following link to quickly install these extensions. Here is the extension.json . https://code.visualstudio.com/docs/editor/extension-gallery#_workspace-recommended-extensions

API-AI

Intents ------ ------ An intent defines how the bot should react to what the user says. An intent in your agent represents a mapping between what a user says and what action should be taken by your product. Every intent you create should correspond to one question. In the intents you will write all the different ways of how those questions may be phrased by your customers. Don’t worry, you won’t have to write all of them. API.AI is using machine learning to train your agent to understand a lot more variations based on the examples you provide in intents. User Says --------- We can have several 'User Says' for a single intent.So we have input many different variations in which the user can as for the same intent. The API.AI platform uses machine learning to train agents to understand more variations of these examples. Even with a small number of examples, the agent can understand a lot of variations. You can try it with this agent. The more examples you add, the better the agent...