Hi all,
Can you help me with the following double for loop, writing it more cleanly and make it work for 'lc3'
The output needs to be as follows:
Can you help me with the following double for loop, writing it more cleanly and make it work for 'lc3'
1 2 3 4 5 6 7 8 9 10 |
old = 'car' new = 'scooter' loadcases = { 'lc1' : [[ 'car' , 'red' , '10' ], [ 'train' , 'blue' , '20' ], [ 'airplane' , 'gray' , '300' ]], 'lc2' : [[ 'bike' , 'red' , '10' ], [ 'train' , 'blue' , '20' ], [ 'car' , 'gray' , '300' ]], 'lc3' : 'car' } # this works for lc1 and lc2 but not for lc3, how can I incorporate this too? for lc in loadcases: for element in loadcases[lc]: if element[ 0 ] = = old: element[ 0 ] = new |
Output:{'lc1': [['scooter', 'red', '10'], ['train', 'blue', '20'], ['airplane', 'gray', '300']], 'lc2': [['bike', 'red', '10'], ['train', 'blue', '20'], ['scooter', 'gray', '300']], 'lc3': 'scooter'}