Download (right-click, save target as ...) this page as a jupyterlab notebook from:

Laboratory 4.1 - TH


Exercise Set 4.1: Data Structures

LAST NAME, FIRST NAME

R00000000

ENGR 1330 ES-4.1 - Homework

In [1]:
# Preamble script block to identify host, user, and kernel
import sys
! hostname
! whoami
print(sys.executable)
print(sys.version)
print(sys.version_info)
atomickitty
sensei
/opt/jupyterhub/bin/python3
3.8.10 (default, Jun  2 2021, 10:49:15) 
[GCC 9.4.0]
sys.version_info(major=3, minor=8, micro=10, releaselevel='final', serial=0)

Exercise 1: List Manipulation

For the list given below, index and pick all the elements from index positions 3 to 10. Then, calculate the sum and the length of the elements from index positions 3 to 7. Print the sliced list and the values of the sum and the sliced list.

[22, 45, 54, 87, 10, 97, 88, 75, 99, 11, 19, 39, 47, 81, 84]

In [ ]:
# Make the given list; then print the contents
In [ ]:
# slice the list from positions 3 to 10 including 10; put the slice into a new list
In [ ]:
# print the new list
In [ ]:
# slice the new list above from positions 3 to 7 | including 7 ; put the slice into another new list
In [ ]:
# print the another new list
In [ ]:
# find the sum of the another new list
In [ ]:
# find the length of the another new list

Exercise 2: Dictionary Manipulation

From the nested dictionary given below, index and pick the string 'hello'.

{'k1':[1,2,3,{'tricky':['oh','man','inception',{'target':[1,2,3,'hello']}]}]}

In [ ]:
# create the dictionary, give it a name; use the curly bracket construction method
In [ ]:
# lookup in the dictionary using keys and indices to find the object 'hello' 
In [ ]: