27def create_new_block(previous_block, data):
28 index = previous_block.index + 1
29 timestamp = time.time()
30 hash = calculate_hash(index, previous_block.hash, timestamp, data, "")31 return Block(index, previous_block.hash, timestamp, data, hash)
32
33
3
4
5class Block:
6 def __init__(self, index, previous_hash, timestamp, data, hash): 7 self.index = index
8 self.previous_hash = previous_hash
9 self.timestamp = timestamp
Defining a local variable or function with the same name as a built-in object makes the built-in object unusable within the current scope and makes the code prone to bugs.
dict = {} # dict is a Python builtin!
for idx, student in enumerate(students):
dict[student] = idx
roll_number = {}
for idx, student in enumerate(students):
roll_number[student] = idx