Dictionary Operations

Post Reply
admin
Site Admin
Posts: 119
Joined: Fri May 10, 2024 2:46 pm
Location:

Dictionary Operations

Post by admin »

Dictionary:


A dictionary in Python is a data structure that stores the value in value:key pairs. The most common associated method of dictionaries are get(), keys(), values(), items(), update(), pop(), clear() etc.
Example: Dict = {1: ‘ICAI', 2: 'For', 3: ‘CA’}
As you can see from the example, data is stored in key: value pairs in dictionaries, which makes it easier to find values.
Dictionary vs Json

Code: Select all

def get_coordinates():
    x = 13.339
    y = 80.1425
    return x, y

coordinates = get_coordinates()
print(coordinates


Code: Select all

person = {'name': 'John', 'age': 25, 'city': 'New York'}




#Client Ledger (Name -> Balance)
ledger = {"Ramesh": 12000, "Suresh": -5000}
print("Ramesh's balance:", ledger["Ramesh"])
#Update balance

Code: Select all

ledger["Suresh"] += 2000
print("Updated Suresh's balance:", ledger["Suresh"])
#Looping through ledger

Code: Select all

for client, balance in ledger.items():
    print(client, "=>", balance)
print(person['name']) # Output: John
[/code]
admin
Site Admin
Posts: 119
Joined: Fri May 10, 2024 2:46 pm
Location:

Re: Dictionary Operations

Post by admin »

test
Attachments
code.zip
(1.07 KiB) Downloaded 5 times
Post Reply