The easiest way to split list into equal sized chunks is to use a slice operator successively and shifting initial and final position by a fixed number. In following example, a list with 12 elements is present. We split it into 3 lists each of length 4 ,
Tuple is one of the standard data types in Python. It is an immutable sequence of objects. Tuple object is created by putting one or more objects, not necessarily of same type, separated by comma. The collection can optionally be put inside parentheses. ,
A tuple object is generally used to define a data structure with comma separated field values put in parentheses. Value of each field is identified by index in tuple. , Named tuple is defined with field names specified in its definition. namedtuple() factory function allows creation of tuple with name fields. Field values can now be accessed by name in addition to index. The function .....
It is possible to iterate over each key value pair in a dictionary by the expression , Since value component of each item is itself a dictionary in nested Python dictionary, length of each sub-dictionary is len(v). Perform cumulative addition over the loop to obtain count of all elements , , A more compact representation of above will be: ,
A Python dictionary object is a collection of key-value pairs. Each item in a dictionary consists of a value associated with key. The association is defined by putting : between them. Such key-value pairs, separated by comma and included within curly brackets, forms a dictionary object. Key component of item must be an immutable object and unique in the collection. Value component may be re.....
Tuple is defined as an ordered collection of any Python objects enclosed in parentheses. Hence, a tuple can very well be one of the items in the collection. , In this example, item at index number 1 in t1 is a tuple itself. Hence it can be retrieved using the index as: , Further items of enclosed tuples can also be retrieved using their internal index ,
Standard data types of Python include numeric data types, sequence types and dictionary which is a collection of key-value pairs. Objects of numeric data types are either integers, floats or complex numbers. Integers are whole numbers, whereas floats have a fractional part. Complex number has two components, real and imaginary part. A float number multiplied by j which is an imaginary value.....
PostgreSql database is by default installed on port number 5432. Python interface to PostgreSql is provided by installing psycopg2 module. Assuming that test database and employee table with fname, sname, age, gender and salary fields is available. First establish connection and obtain cursor object by following statements in Python script. , Data to be inserted in employee table is stored .....
Sign up now to get your own personalized profile!
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more