I have a list of stocks and positions as tuples. Positive for buy, negative for sell. Example:
p = [('AAPL', 50), ('AAPL', -50), ('RY', 100), ('RY', -43)]
How can I sum the positions of stocks, to get the current holdings?
result = [('AAPL', 0), ('RY', 57)]
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…