Page 1 of 1

Dictionary Operations

Posted: Mon May 27, 2024 9:36 am
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]

Re: Dictionary Operations

Posted: Sun Aug 10, 2025 12:22 pm
by admin
test