Buen-Mendeleev-List, Tuple, and Set in Python
Buen-Mendeleev-List, Tuple, and Set in Python
Ianrain N. Buen
G9-Mendeleev
Specific Objectives
Materials
Pen
Bond paper or intermediate paper
Lesson
List
Lists are used to store multiple items in a single variable.
1
Lists are one of 4 built-in data types in Python used to store collections of data, the
other 3 are Tuple, Set, and Dictionary, all with different qualities and usage.
-6 -5 -4 -3 -2 -1
2 6 654 8 23 765
0 1 2 3 4 5
Insert -- in between
2
pop with index number
3
Sort and Reverse
- immutable
4
EXERCISES
Directions:Write your answers on the space provided. Make sure to submit your HSMGW
on time.
BASIC
Differentiate lists from tuple.
- Lists are just like the arrays, declared in other languages. Lists need not be
homogeneous always which makes it a most powerful tool in Python. In Python,
the list is a type of container in Data Structures, which is used to store multiple
data at the same time. Lists are a useful tool for preserving a sequence of data and
further iterating over it. Tuple is also a sequence data type that can contain
elements of different data types, but these are immutable in nature. In other words,
a tuple is a collection of Python objects separated by commas. The tuple is faster
than the list because of static in nature.
INTERMEDIATE
Code Output
>>> xx = [6,23,765,3,65,87,90,34,54,2005] [[6, 23, 765, 3, 65, 87, 90, 34, 54,
>>> yy = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t', 2005], ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'u','v','w','x','y','z'] 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
>>>zz = [xx,yy] 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']]
5
>>> xx[1] 23
>>> 'i'
>>> xx.pop() 2005
>>> xx.insert(4,78) [6, 23, 765, 3, 78, 65, 87, 90, 34,
54, 2005]
[6, 23, 765, 3, 78, 65, 87, 90, 34,
>>> xx.append(1) 54, 2005, 1]
3211
>>> sum(xx)
1
>>> min(xx)
>>> max(xx) 2005
[6, 23, 765, 3, 78, 65, 87, 90, 34,
>>> xx[:10] 54]
ADVANCED:
>>> yy[15] + yy[2] + yy[18] + yy[7] + yy[18] pcshs
>>> yy[2] + str(xx[0]) c6
>>>yy[15] + yy[17] + yy[14] + yy[6] + ' ' + str (min(xx)) prog 1
>>>yy[15] + yy[17] + yy[14] + yy[6] + yy[17] + yy[0] + yy[12] + yy[12] programming 1
+ yy[8] + yy[13] + yy[6] + ' ' + str ( min(xx))
Closure
6
B. If you have questions in mind, please use the space below to address it.
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
References
https://www.guru99.com/variables-in-python.html