Put the data in a data structure (list, dict, etc.) using python

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • feuerk
    New Member
    • Oct 2020
    • 3

    Put the data in a data structure (list, dict, etc.) using python

    I dont even know where to start.





    Code:
    import electricity
    utility = electricity.get_utility()
    I am having trouble organizing the dataset into a matrix of some sort with the columns : "number" "name" "state" "type"
  • Vanisha
    New Member
    • Jan 2023
    • 26

    #2
    Sure, here are some examples of how to put data into different data structures using Python:

    List:
    A list is a collection of items that are ordered and changeable. Here's an example of how to create a list and add some data to it:
    my_list = [1, 2, 3, "four", 5.0]
    Dictionary:
    A dictionary is a collection of key-value pairs that are unordered and changeable. Here's an example of how to create a dictionary and add some data to it:
    my_dict = {"name": "John", "age": 30, "city": "New York"}
    Tuple:
    A tuple is a collection of items that are ordered and unchangeable. Here's an example of how to create a tuple:
    my_tuple = (1, 2, 3, "four", 5.0)
    A set is a collection of unique items that are unordered and unchangeable. Here's an example of how to create a set:
    my_set = {1, 2, 3, "four", 5.0}
    Note: You can add data to a list, dictionary, or set using the append() method, update() method, and add() method, respectively.
    If you want to learn more, join CETPA Infotech.

    Comment

    Working...