0
0
Blockchain / Solidityprogramming~30 mins

Efficient data structures in Blockchain / Solidity - Mini Project: Build & Apply

Choose your learning style9 modes available
Efficient Data Structures in Blockchain
📖 Scenario: You are building a simple blockchain ledger to store transactions. Each transaction has a unique ID and an amount. Efficient data storage is important to quickly find and update transactions.
🎯 Goal: Create a dictionary to store transactions, add a threshold to filter large transactions, use dictionary comprehension to select only large transactions, and print the filtered transactions.
📋 What You'll Learn
Create a dictionary called transactions with exact transaction IDs and amounts
Create a variable called threshold with the value 1000
Use dictionary comprehension with transaction_id and amount to select transactions with amounts greater than threshold
Print the filtered dictionary called large_transactions
💡 Why This Matters
🌍 Real World
Blockchains store many transactions and need fast ways to find important data like large transfers.
💼 Career
Understanding efficient data structures helps blockchain developers optimize storage and speed in real applications.
Progress0 / 4 steps
1
Create the transactions dictionary
Create a dictionary called transactions with these exact entries: 'tx1001': 500, 'tx1002': 1500, 'tx1003': 700, 'tx1004': 2500, 'tx1005': 300
Blockchain / Solidity
Need a hint?

Use curly braces {} to create a dictionary with keys as transaction IDs and values as amounts.

2
Set the threshold for large transactions
Create a variable called threshold and set it to 1000
Blockchain / Solidity
Need a hint?

Just assign the number 1000 to the variable threshold.

3
Filter large transactions using dictionary comprehension
Use dictionary comprehension with transaction_id and amount to create a new dictionary called large_transactions that contains only transactions where amount > threshold
Blockchain / Solidity
Need a hint?

Use {key: value for key, value in dict.items() if condition} to filter the dictionary.

4
Print the filtered large transactions
Write print(large_transactions) to display the dictionary of large transactions
Blockchain / Solidity
Need a hint?

Use the print() function to show the filtered dictionary.