# 1.27 Itse1359-1090-lists part 2  (Page 4/4)

 Page 4 / 4

## More on nested elements

The program in Listing 4 illustrates some additional aspects of nested elements.

Listing 4 . More nested elements.
```# Illustrates more nested elements ##----------------------------------------- print("Create and print a list\with 3 nested elements") listA = [[2,4],[8,16,32],[64,128,256,512]]print(listA) print("Number of elements is:")print(len(listA)) print("Length of Element 0 is")print(len(listA[0]))print("Length of Element 1 is") print(len(listA[1])) print("Length of Element 2 is")print(len(listA[2]))```

## Create a list of lists

This program defines a three-element list containing three nested lists.

In other words, each of the elements in the outer list is itself a list.

## Inner lists are different lengths

Furthermore, the lengths of the inner nested lists are not the same. The lengths of the inner nested lists are 2, 3, and 4 elements each, respectively.

## Program behavior and output

The output from the program is shown in Figure 5 . The program displays the entire list, and then gets and displays the lengths of each of the nested lists.

Figure 5 . Output from more nested elements.
```Create and print a list with 3 nested elements [[2, 4], [8, 16, 32], [64, 128, 256, 512]]Number of elements is: 3Length of Element 0 is 2Length of Element 1 is 3Length of Element 2 is 4```

## Getting the length of a nested list

Note in particular the syntax used to pass a parameter to the len() method in order to get the length of a nested list (len(listA[1]) ) .

## Arrays -- not for beginners

If you are a beginning programmer, you may want to skip this section. If you are an experienced programmer, you may have observed that a Python lists bear a striking resemblance to arrays in other programming environments.

## Python lists are more powerful

However, Python lists are more powerful than the arrays I am aware of in other programming environments, including Java.

## Sub-arrays can be different sizes

For example as in Java, when a Python list is used to construct a multidimensional array, the sub arrays don't have to be of the same size.

## Types can also be different

However, unlike Java, the elements in the array don't even have to be of the same type (granted that the elements in a Java array can be of different types so long as there is an inheritance or Interface relationship among them).

## A three-dimensional array program

The program in Listing 5 might represent what an experienced programmer would consider to be athree-dimensional array of integer data in some other programming environment.

Listing 5 . A three-dimensional array program.
```# Illustrates a three-dimensional array list ##---------------------------------------------------- print("Create and print a\three-dimensional array list") listA = [[[[1],[2]],[[3],[4]]],[[[5],[6]],[[7],[8]]]] print(listA)print("Print each element") print(listA[0][0][0]) print(listA[0][0][1]) print(listA[0][1][0]) print(listA[0][1][1]) print(listA[1][0][0]) print(listA[1][0][1]) print(listA[1][1][0]) print(listA[1][1][1])```

## Triple-square-bracket notation

Pay particular attention to the triple square bracket notation that is used to access and print each element in the array. This is very similar to thesyntax in other programming languages.

## Visualization of a three-dimensional array

Figure 6 shows a visualization of the three-dimensional array pointed to by the variable named listA in Listing 5 . In programming, we deal with arrays having one, two, three or more dimensions. As you can see, even a three-dimensional array is arelatively complex structure.

Figure 6. Visualization of a three-dimensional array.

## Program behavior

This program

• Creates and populates the list that represents a three-dimensional array.
• Displays the entire array as a set of nested lists.
• Displays the contents of each element in the array.

## Output from a three-dimensional array program

The output from the program is shown in Figure 7 . The triple-square-bracket notation in the program of Listing 5 is essentially the same notation that would be used to access the individual elements in athree-dimensional array in C, C++, or Java.

Figure 7 . Output from a three-dimensional array program.
```Create and print a three-dimensional array list [[[[1], [2]], [[3], [4]]], [[[5], [6]], [[7], [8]]]] Print each element[1] [2][3] [4][5] [6][7] [8]```

There is quite a lot more that you will need to learn about lists. However, I will defer that discussion for a future module where I discuss the use of a listas a data structure or a container .

## Miscellaneous

This section contains a variety of miscellaneous information.

Housekeeping material
• Module name: Itse1359-1090-Lists Part 2
• File: Itse1359-1090.htm
• Published: 10/15/14
• Revised: 01/31/16
Disclaimers:

Financial : Although the Connexions site makes it possible for you to download a PDF file for thismodule at no charge, and also makes it possible for you to purchase a pre-printed version of the PDF file, you should beaware that some of the HTML elements in this module may not translate well into PDF.

I also want you to know that, I receive no financial compensation from the Connexions website even if you purchase the PDF version of the module.

In the past, unknown individuals have copied my modules from cnx.org, converted them to Kindle books, and placed them for sale on Amazon.com showing me as the author. Ineither receive compensation for those sales nor do I know who does receive compensation. If you purchase such a book, please beaware that it is a copy of a module that is freely available on cnx.org and that it was made and published withoutmy prior knowledge.

Affiliation : I am a professor of Computer Information Technology at Austin Community College in Austin, TX.

-end-

where we get a research paper on Nano chemistry....?
what are the products of Nano chemistry?
There are lots of products of nano chemistry... Like nano coatings.....carbon fiber.. And lots of others..
learn
Even nanotechnology is pretty much all about chemistry... Its the chemistry on quantum or atomic level
learn
da
no nanotechnology is also a part of physics and maths it requires angle formulas and some pressure regarding concepts
Bhagvanji
Preparation and Applications of Nanomaterial for Drug Delivery
revolt
da
Application of nanotechnology in medicine
what is variations in raman spectra for nanomaterials
I only see partial conversation and what's the question here!
what about nanotechnology for water purification
please someone correct me if I'm wrong but I think one can use nanoparticles, specially silver nanoparticles for water treatment.
Damian
yes that's correct
Professor
I think
Professor
Nasa has use it in the 60's, copper as water purification in the moon travel.
Alexandre
nanocopper obvius
Alexandre
what is the stm
is there industrial application of fullrenes. What is the method to prepare fullrene on large scale.?
Rafiq
industrial application...? mmm I think on the medical side as drug carrier, but you should go deeper on your research, I may be wrong
Damian
How we are making nano material?
what is a peer
What is meant by 'nano scale'?
What is STMs full form?
LITNING
scanning tunneling microscope
Sahil
how nano science is used for hydrophobicity
Santosh
Do u think that Graphene and Fullrene fiber can be used to make Air Plane body structure the lightest and strongest. Rafiq
Rafiq
what is differents between GO and RGO?
Mahi
what is simplest way to understand the applications of nano robots used to detect the cancer affected cell of human body.? How this robot is carried to required site of body cell.? what will be the carrier material and how can be detected that correct delivery of drug is done Rafiq
Rafiq
if virus is killing to make ARTIFICIAL DNA OF GRAPHENE FOR KILLED THE VIRUS .THIS IS OUR ASSUMPTION
Anam
analytical skills graphene is prepared to kill any type viruses .
Anam
Any one who tell me about Preparation and application of Nanomaterial for drug Delivery
Hafiz
what is Nano technology ?
write examples of Nano molecule?
Bob
The nanotechnology is as new science, to scale nanometric
brayan
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Damian
Is there any normative that regulates the use of silver nanoparticles?
what king of growth are you checking .?
Renato
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
why we need to study biomolecules, molecular biology in nanotechnology?
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
why?
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
Got questions? Join the online conversation and get instant answers!