DevOps, Day - 14

DevOps, Day - 14

Data Structures for DevOps

Please go through Python data types➡️ Here

Data Structures in Python

In Python, a data structure is a way of organizing and storing data in a computer program, so that it can be accessed and used efficiently. Python provides several built-in data structures, including:

  • Lists: Ordered collection of items, and are mutable (elements can be changed).

  • Tuples: Ordered collection of items, and are immutable (elements cannot be changed).

  • Sets: Unordered collection of unique elements, and are mutable.

  • Dictionaries: Collection of key-value pairs, and are mutable.

Tasks:

  1. Give the Difference between List, Tuple and Set. Do Handson and put screenshots as per your understanding.

    • List: Consider the below example, where 'a' contains[23,56,98]

      When you try to add value to the List... we can observe ordered elements in the output, as 37 was added in the last, the order of elements in a list is preserved based on the order in which they were added. [Because List is a collection of ordered elements]

    • Tuple: consider the below example, where 'a' contains(9,10,11)

      As we know tuples are immutable, hence cannot add or remove elements from the tuple.

    • Set: consider the below example, where 'a' contains{4,2,7}

      When you try to add value to the set... we can observe unordered elements in the output, as 45 was not added in the last, it was added somewhere in the middle**[Because set is a collection of unordered elements]**

      When you try to add an already existing element to the set, you can observe unique values.[Because set holds unique values]

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

    step 1: Create a dictionary with the above contents

    step 2: If you need only key numbers

    step 3: if you need only values

    step 4: If you need a particular tool from the dictionary

  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.

    step 1: create a list with the above-mentioned strings

    step 2: Now add Digital Ocean to the list

    step 3: Now sort in alphabetical order

Thank you so much for reading.

Follow me on LinkedIn to see interesting posts like this : )

Linkedin