This helper function is responsible for obtaining the addresses responsible for sending the transaction. This information is found within multiple nested dictionaries. As there could be more than one input, we must iterate through one or more elements in the input list. As we find input addresses, we add them to an input list that's instantiated on line 123, as shown in the following code:
116 def get_inputs(tx):
117 """
118 The get_inputs function is a small helper function that returns
119 input addresses for a given transaction
120 :param tx: A single instance of a Bitcoin transaction
121 :return: inputs, a list of inputs
122 """
123 inputs = []
For each input, there's a dictionary key, prev_out, the value of which is another dictionary. The information we're looking for is mapped to the addr key within this inner dictionary. We append these addresses to our input list, which we return on line 126 after the for loop execution ends:
124 for input_addr in tx['inputs']:
125 inputs.append(input_addr['prev_out']['addr'])
126 return inputs