Skip to main content

Command Palette

Search for a command to run...

Day 14 Task: Python Data Types and Data Structures for DevOps

Published
1 min read
Day 14 Task: Python Data Types and Data Structures for DevOps

Task 1:

Give the Difference between List, Tuple, and set with an example.

A list is a collection of heterogeneous element which is mutable. It is defined using [ ] bracket. If you need a collection with duplicates and want the ability to modify it, use a list. E.g:

list=[‘Creta’, ‘Baleno’, 1,4.5]
list.append(‘Punch’)
print(list)

A tuple is a collection of heterogeneous element which is immutable. It is defined using the ( ) bracket. If you need an immutable collection, use a tuple. E.g:

tuple=(‘a’,2,5,’b’)
tuple.append(4) #This line will throw error as tuple is immutable.
print(list)

Sets is a collection of unique elements. It is defined by { } block. If you need a collection of unique elements, use a set. E.g:

set= {1,2,3,4}
set.add(5)
print(set)

Task 2:

Create below Dictionary and use Dictionary methods to print your favourite tool just by using the keys of the Dictionary.

fav_tools =
{
  1:"Linux",
  2:"Git",
  3:"Docker",
  4:"Kubernetes",
  5:"Terraform",
  6:"Ansible",
  7:"Chef"
}

set= {1,2,3,4}
    set.add(5)
    print(set)

Task 3:

Create a List of cloud service providers eg.

cloud_providers = ["AWS","GCP","Azure"]

Write a program to add Digital Ocean to the list of cloud_providers and sort the list in alphabetical order.

Happy Learning!!!