Download as pdf or txt
Download as pdf or txt
You are on page 1of 76

Essential Software

Dr. Muhammad Yousuf Tufail

Department of Mathematics
Institute of Business Administration.
‡ Yousuf Tufail ¯ Yousuf Tufail
ytufail@iba.edu.pk

Lecture 3 & 4

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 1 / 10


Lists

fam heights=[”John”, 1.64, ”Hazel”, 1.42, ”mom”, 1.56, ”dad”, 1.80]

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 2 / 10


Lists

fam heights=[”John”, 1.64, ”Hazel”, 1.42, ”mom”, 1.56, ”dad”, 1.80]

Calling entries from the list

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 2 / 10


Lists

fam heights=[”John”, 1.64, ”Hazel”, 1.42, ”mom”, 1.56, ”dad”, 1.80]

Calling entries from the list


print(fam heights[3])

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 2 / 10


Lists

fam heights=[”John”, 1.64, ”Hazel”, 1.42, ”mom”, 1.56, ”dad”, 1.80]

Calling entries from the list


print(fam heights[3])
1.42

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 2 / 10


Lists

fam heights=[”John”, 1.64, ”Hazel”, 1.42, ”mom”, 1.56, ”dad”, 1.80]

Calling entries from the list


print(fam heights[3])
1.42
print(fam heights[2],fam heights[3])

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 2 / 10


Lists

fam heights=[”John”, 1.64, ”Hazel”, 1.42, ”mom”, 1.56, ”dad”, 1.80]

Calling entries from the list


print(fam heights[3])
1.42
print(fam heights[2],fam heights[3])
Hazel 1.42

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 2 / 10


Lists

fam heights=[”John”, 1.64, ”Hazel”, 1.42, ”mom”, 1.56, ”dad”, 1.80]

Calling entries from the list


print(fam heights[3])
1.42
print(fam heights[2],fam heights[3])
Hazel 1.42

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 2 / 10


Lists with in a list

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 3 / 10


Lists with in a list

It is better to represent the heights information in the form of lists with in


a list format, as below:

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 3 / 10


Lists with in a list

It is better to represent the heights information in the form of lists with in


a list format, as below:
fam heights new=[[”John”, 1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”,
1.80]]

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 3 / 10


Lists with in a list

It is better to represent the heights information in the form of lists with in


a list format, as below:
fam heights new=[[”John”, 1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”,
1.80]]
print(fam heights new[0])

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 3 / 10


Lists with in a list

It is better to represent the heights information in the form of lists with in


a list format, as below:
fam heights new=[[”John”, 1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”,
1.80]]
print(fam heights new[0])
[’John’, 1.64]

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 3 / 10


Lists with in a list

It is better to represent the heights information in the form of lists with in


a list format, as below:
fam heights new=[[”John”, 1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”,
1.80]]
print(fam heights new[0])
[’John’, 1.64]
print(fam heights new[3])

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 3 / 10


Lists with in a list

It is better to represent the heights information in the form of lists with in


a list format, as below:
fam heights new=[[”John”, 1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”,
1.80]]
print(fam heights new[0])
[’John’, 1.64]
print(fam heights new[3])
[’dad’, 1.80]

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 3 / 10


Lists with in a list

It is better to represent the heights information in the form of lists with in


a list format, as below:
fam heights new=[[”John”, 1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”,
1.80]]
print(fam heights new[0])
[’John’, 1.64]
print(fam heights new[3])
[’dad’, 1.80]
It is one of the best possible way to represent the heights information in
the form of lists.

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 3 / 10


Lists with in a list

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 4 / 10


Lists with in a list
It is better to represent the heights information in the form of lists with in
a list format, as below:

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 4 / 10


Lists with in a list
It is better to represent the heights information in the form of lists with in
a list format, as below:
fam heights new=[[”John”, 1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”,
1.80]]

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 4 / 10


Lists with in a list
It is better to represent the heights information in the form of lists with in
a list format, as below:
fam heights new=[[”John”, 1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”,
1.80]]
It is one of the best possible way to represent the heights information in
the form of lists.

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 4 / 10


Lists with in a list
It is better to represent the heights information in the form of lists with in
a list format, as below:
fam heights new=[[”John”, 1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”,
1.80]]
It is one of the best possible way to represent the heights information in
the form of lists.
Example
Find first and third elements in the list

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 4 / 10


Lists with in a list
It is better to represent the heights information in the form of lists with in
a list format, as below:
fam heights new=[[”John”, 1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”,
1.80]]
It is one of the best possible way to represent the heights information in
the form of lists.
Example
Find first and third elements in the list

Solution

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 4 / 10


Lists with in a list
It is better to represent the heights information in the form of lists with in
a list format, as below:
fam heights new=[[”John”, 1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”,
1.80]]
It is one of the best possible way to represent the heights information in
the form of lists.
Example
Find first and third elements in the list

Solution
print(fam heights new[0])

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 4 / 10


Lists with in a list
It is better to represent the heights information in the form of lists with in
a list format, as below:
fam heights new=[[”John”, 1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”,
1.80]]
It is one of the best possible way to represent the heights information in
the form of lists.
Example
Find first and third elements in the list

Solution
print(fam heights new[0])
[’John’, 1.64]

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 4 / 10


Lists with in a list
It is better to represent the heights information in the form of lists with in
a list format, as below:
fam heights new=[[”John”, 1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”,
1.80]]
It is one of the best possible way to represent the heights information in
the form of lists.
Example
Find first and third elements in the list

Solution
print(fam heights new[0])
[’John’, 1.64]
print(fam heights new[2])

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 4 / 10


Lists with in a list
It is better to represent the heights information in the form of lists with in
a list format, as below:
fam heights new=[[”John”, 1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”,
1.80]]
It is one of the best possible way to represent the heights information in
the form of lists.
Example
Find first and third elements in the list

Solution
print(fam heights new[0])
[’John’, 1.64]
print(fam heights new[2])
[’mom’, 1.56]

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 4 / 10


Lists with in a list
It is better to represent the heights information in the form of lists with in
a list format, as below:
fam heights new=[[”John”, 1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”,
1.80]]
It is one of the best possible way to represent the heights information in
the form of lists.
Example
Find first and third elements in the list

Solution
print(fam heights new[0])
[’John’, 1.64]
print(fam heights new[2])
[’mom’, 1.56]

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 4 / 10


Subsetting lists and slicing

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 5 / 10


Subsetting lists and slicing
fam heights new=[[”John”, 1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”,
1.80]]

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 5 / 10


Subsetting lists and slicing
fam heights new=[[”John”, 1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”,
1.80]]
There are two possible ways to call an element from the list which is
explained as below:

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 5 / 10


Subsetting lists and slicing
fam heights new=[[”John”, 1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”,
1.80]]
There are two possible ways to call an element from the list which is
explained as below:

Example
Find the fourth element from the given list using python.

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 5 / 10


Subsetting lists and slicing
fam heights new=[[”John”, 1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”,
1.80]]
There are two possible ways to call an element from the list which is
explained as below:

Example
Find the fourth element from the given list using python.

Solution

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 5 / 10


Subsetting lists and slicing
fam heights new=[[”John”, 1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”,
1.80]]
There are two possible ways to call an element from the list which is
explained as below:

Example
Find the fourth element from the given list using python.

Solution
print(fam heights new[3])

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 5 / 10


Subsetting lists and slicing
fam heights new=[[”John”, 1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”,
1.80]]
There are two possible ways to call an element from the list which is
explained as below:

Example
Find the fourth element from the given list using python.

Solution
print(fam heights new[3])
[’dad’, 1.80]

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 5 / 10


Subsetting lists and slicing
fam heights new=[[”John”, 1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”,
1.80]]
There are two possible ways to call an element from the list which is
explained as below:

Example
Find the fourth element from the given list using python.

Solution
print(fam heights new[3])
[’dad’, 1.80]

An alternative way to get the above results is as below:

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 5 / 10


Subsetting lists and slicing
fam heights new=[[”John”, 1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”,
1.80]]
There are two possible ways to call an element from the list which is
explained as below:

Example
Find the fourth element from the given list using python.

Solution
print(fam heights new[3])
[’dad’, 1.80]

An alternative way to get the above results is as below:


print(fam heights new[-1])

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 5 / 10


Subsetting lists and slicing
fam heights new=[[”John”, 1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”,
1.80]]
There are two possible ways to call an element from the list which is
explained as below:

Example
Find the fourth element from the given list using python.

Solution
print(fam heights new[3])
[’dad’, 1.80]

An alternative way to get the above results is as below:


print(fam heights new[-1])# An alternative way

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 5 / 10


Subsetting lists and slicing
fam heights new=[[”John”, 1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”,
1.80]]
There are two possible ways to call an element from the list which is
explained as below:

Example
Find the fourth element from the given list using python.

Solution
print(fam heights new[3])
[’dad’, 1.80]

An alternative way to get the above results is as below:


print(fam heights new[-1])# An alternative way
[’dad’, 1.80]
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 5 / 10
Subsetting lists and slicing
fam heights new=[[”John”, 1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”,
1.80]]
There are two possible ways to call an element from the list which is
explained as below:

Example
Find the fourth element from the given list using python.

Solution
print(fam heights new[3])
[’dad’, 1.80]

An alternative way to get the above results is as below:


print(fam heights new[-1])# An alternative way
[’dad’, 1.80]
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 5 / 10
Subsetting lists and slicing: fam heights new=[[”John”,
1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]
Slicing:

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 6 / 10


Subsetting lists and slicing: fam heights new=[[”John”,
1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]
Slicing:
Example
Find first three values in the list.?

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 6 / 10


Subsetting lists and slicing: fam heights new=[[”John”,
1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]
Slicing:
Example
Find first three values in the list.?
Remember,

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 6 / 10


Subsetting lists and slicing: fam heights new=[[”John”,
1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]
Slicing:
Example
Find first three values in the list.?
Remember, Remember,

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 6 / 10


Subsetting lists and slicing: fam heights new=[[”John”,
1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]
Slicing:
Example
Find first three values in the list.?
Remember, Remember, Remember!

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 6 / 10


Subsetting lists and slicing: fam heights new=[[”John”,
1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]
Slicing:
Example
Find first three values in the list.?
Remember, Remember, Remember!

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 6 / 10


Subsetting lists and slicing: fam heights new=[[”John”,
1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]
Slicing:
Example
Find first three values in the list.?
Remember, Remember, Remember!

When you write [0:n] for the selection in python

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 6 / 10


Subsetting lists and slicing: fam heights new=[[”John”,
1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]
Slicing:
Example
Find first three values in the list.?
Remember, Remember, Remember!

When you write [0:n] for the selection in python, it means 0 (which
represent the first position) is included.

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 6 / 10


Subsetting lists and slicing: fam heights new=[[”John”,
1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]
Slicing:
Example
Find first three values in the list.?
Remember, Remember, Remember!

When you write [0:n] for the selection in python, it means 0 (which
represent the first position) is included. But n (which represent the n+1
position) is not included.

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 6 / 10


Subsetting lists and slicing: fam heights new=[[”John”,
1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]
Slicing:
Example
Find first three values in the list.?
Remember, Remember, Remember!

When you write [0:n] for the selection in python, it means 0 (which
represent the first position) is included. But n (which represent the n+1
position) is not included. Therefore [0:n] means select all the positions
from 0 to (n-1).

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 6 / 10


Subsetting lists and slicing: fam heights new=[[”John”,
1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]
Slicing:
Example
Find first three values in the list.?
Remember, Remember, Remember!

When you write [0:n] for the selection in python, it means 0 (which
represent the first position) is included. But n (which represent the n+1
position) is not included. Therefore [0:n] means select all the positions
from 0 to (n-1). i.e., [0:3] means select all the positions from 0 to 2.

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 6 / 10


Subsetting lists and slicing: fam heights new=[[”John”,
1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]
Slicing:
Example
Find first three values in the list.?
Remember, Remember, Remember!

When you write [0:n] for the selection in python, it means 0 (which
represent the first position) is included. But n (which represent the n+1
position) is not included. Therefore [0:n] means select all the positions
from 0 to (n-1). i.e., [0:3] means select all the positions from 0 to 2.
Solution
print(fam heights new[0:3])

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 6 / 10


Subsetting lists and slicing: fam heights new=[[”John”,
1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]
Slicing:
Example
Find first three values in the list.?
Remember, Remember, Remember!

When you write [0:n] for the selection in python, it means 0 (which
represent the first position) is included. But n (which represent the n+1
position) is not included. Therefore [0:n] means select all the positions
from 0 to (n-1). i.e., [0:3] means select all the positions from 0 to 2.
Solution
print(fam heights new[0:3])
[[”John”, 1.64], [”Hazel”, 1.42], [”mom”, 1.56]]
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 6 / 10
Subsetting lists and slicing: fam heights new=[[”John”,
1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]

Example
Find the first two values from the given list.

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 7 / 10


Subsetting lists and slicing: fam heights new=[[”John”,
1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]

Example
Find the first two values from the given list.

Solution

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 7 / 10


Subsetting lists and slicing: fam heights new=[[”John”,
1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]

Example
Find the first two values from the given list.

Solution
print(fam heights new[0:2])

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 7 / 10


Subsetting lists and slicing: fam heights new=[[”John”,
1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]

Example
Find the first two values from the given list.

Solution
print(fam heights new[0:2])
[[”John”, 1.64], [”Hazel”, 1.42]]

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 7 / 10


Subsetting lists and slicing: fam heights new=[[”John”,
1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]

Example
Find all the values in the given list except first value.

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 8 / 10


Subsetting lists and slicing: fam heights new=[[”John”,
1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]

Example
Find all the values in the given list except first value.

Solution

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 8 / 10


Subsetting lists and slicing: fam heights new=[[”John”,
1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]

Example
Find all the values in the given list except first value.

Solution
There are two ways to solve it: Method 1:

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 8 / 10


Subsetting lists and slicing: fam heights new=[[”John”,
1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]

Example
Find all the values in the given list except first value.

Solution
There are two ways to solve it: Method 1:
print(fam heights new[1:4])

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 8 / 10


Subsetting lists and slicing: fam heights new=[[”John”,
1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]

Example
Find all the values in the given list except first value.

Solution
There are two ways to solve it: Method 1:
print(fam heights new[1:4])
[[”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 8 / 10


Subsetting lists and slicing: fam heights new=[[”John”,
1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]

Example
Find all the values in the given list except first value.

Solution
There are two ways to solve it: Method 1:
print(fam heights new[1:4])
[[”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]
Second Method:

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 8 / 10


Subsetting lists and slicing: fam heights new=[[”John”,
1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]

Example
Find all the values in the given list except first value.

Solution
There are two ways to solve it: Method 1:
print(fam heights new[1:4])
[[”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]
Second Method:
print(fam heights new[1:])

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 8 / 10


Subsetting lists and slicing: fam heights new=[[”John”,
1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]

Example
Find all the values in the given list except first value.

Solution
There are two ways to solve it: Method 1:
print(fam heights new[1:4])
[[”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]
Second Method:
print(fam heights new[1:])
[[”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 8 / 10


Subsetting lists and slicing: fam heights new=[[”John”,
1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]

Example
Find all the values in the given list except first value.

Solution
There are two ways to solve it: Method 1:
print(fam heights new[1:4])
[[”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]
Second Method:
print(fam heights new[1:])
[[”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]

This second method is more appropriate than first.

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 8 / 10


Subsetting lists and slicing: fam heights new=[[”John”,
1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]

Example
Find all the values in the given list except first value.

Solution
There are two ways to solve it: Method 1:
print(fam heights new[1:4])
[[”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]
Second Method:
print(fam heights new[1:])
[[”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]

This second method is more appropriate than first.


WHY?
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 8 / 10
Subsetting lists and slicing: fam heights new=[[”John”,
1.64], [”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]

Solution
There are two ways to solve it: Method 1:
print(fam heights new[1:4]
[[”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]
Second Method:
print(fam heights new[1:])
[[”Hazel”, 1.42], [”mom”, 1.56], [”dad”, 1.80]]

This second method is more appropriate than first.


WHY?
Ans. Because (in first method) you need to know how many entries in the
list. However there is no such requirement in the second method.
Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 9 / 10
Some built-in functions

Max/min Function
Suppose A=[1, 3, 7, 11, 9, 2]
print(max(A))
11

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 10 / 10


Some built-in functions

Max/min Function
Suppose A=[1, 3, 7, 11, 9, 2]
print(max(A))
11
print(min(A))

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 10 / 10


Some built-in functions

Max/min Function
Suppose A=[1, 3, 7, 11, 9, 2]
print(max(A))
11
print(min(A))
1

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 10 / 10


Some built-in functions

Max/min Function
Suppose A=[1, 3, 7, 11, 9, 2]
print(max(A))
11
print(min(A))
1
Round function

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 10 / 10


Some built-in functions

Max/min Function
Suppose A=[1, 3, 7, 11, 9, 2]
print(max(A))
11
print(min(A))
1
Round function
a=4.76

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 10 / 10


Some built-in functions

Max/min Function
Suppose A=[1, 3, 7, 11, 9, 2]
print(max(A))
11
print(min(A))
1
Round function
a=4.76
print(round(a))

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 10 / 10


Some built-in functions

Max/min Function
Suppose A=[1, 3, 7, 11, 9, 2]
print(max(A))
11
print(min(A))
1
Round function
a=4.76
print(round(a))
5

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 10 / 10


Some built-in functions

Max/min Function
Suppose A=[1, 3, 7, 11, 9, 2]
print(max(A))
11
print(min(A))
1
Round function
a=4.76
print(round(a))
5
print(round(a, 1))

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 10 / 10


Some built-in functions

Max/min Function
Suppose A=[1, 3, 7, 11, 9, 2]
print(max(A))
11
print(min(A))
1
Round function
a=4.76
print(round(a))
5
print(round(a, 1))
4.8

Dr. Muhammad Yousuf Tufail (IBA.) Essential Software Lecture 3 & 4 10 / 10

You might also like