Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint
Cover Image
Cover Image
Drag to reposition
Contributed Answers

How do you split a list into evenly sized chunks in Python?

A Python list object has n elements. How do you split a list into evenly sized chunks in Python? Give a suitable example.
Answered on 1st Jan, 2018, 0 Views

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 ,

How do we define tuple in Python?

What is a tuple object in Python? How do we define tuple in Python? Can you describe with suitable example ?
Answered on 1st Jan, 2018, 0 Views

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. ,

What are "named tuples" in Python?

What are "named tuples" in Python? How do we form a named tuple object? please explain with a suitable example.
Answered on 1st Jan, 2018, 0 Views

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 .....

How to count elements in a nested Python dictionary?

Python dictionary has len() function which gives number of items od key-value pairs. How to count elements in a nested Python dictionary?
Answered on 30th Dec, 2017, 0 Views

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: ,

How to define a Python dictionary within dictionary?

Can Python dictionary have another dictionary inside it? How to define a Python dictionary within dictionary object? Explain with example
Answered on 30th Dec, 2017, 0 Views

A dictionary object is mutable. Hence one dictionary object can be used as a value component of a key. So we can create a nested dictionary object another dictionary object is defined as value associated with key. ,

What is correct syntax to create Python lists?

What is the correct syntax to create Python lists? Can you give me a suitable exmple to understand this concept.
Answered on 30th Dec, 2017, 0 Views

List is a collection of comma separated objects, not necessarily of same type, and put inside square brackets []. List object is mutable and an item can appear more than once in the collection. ,

What is correct syntax to create Python dictionary?

What is the correct syntax to create Python dictionary object? Can you explain to me this concept with an appropriates example?
Answered on 30th Dec, 2017, 0 Views

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.....

How we can use Python Tuple within a Tuple?

Can a tuple object be used as one of the elements in a tuple itself? How we can use Python Tuple within a Tuple?
Answered on 30th Dec, 2017, 0 Views

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 ,

What are Standard Data Types in Python 3?

What are Standard Data Types in Python 3? Can you Give an example of each data type in Python language.
Answered on 30th Dec, 2017, 0 Views

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.....

How to insert a Python tuple in a PostgreSql database?

Is there a suitable Python module for PostgreSQL database? Show How to insert a Python tuple in a PostgreSql database?
Answered on 30th Dec, 2017, 0 Views

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 .....

loader
Advertisements
Contribution

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.