I need to replace all the strings in Current_List.. that are in AllLimit list with string 'Limits' and replace all the strings that are in AllTech list with sring 'Tech' and count the occurence of 'Limits' and 'Tech'. Im using the below code, which is serving the above purpose. In anyway, can I reduce redundancy in the code.
AllTech = ['Power Lost', 'Failure', 'no Supply']
AllLimit = ['High Temp', 'Low Humid']
current_list = ['High Temp', 'Low Humid', 'Power Lost', 'no Supply' ]
fc = [sub.replace('High Temp', 'Limits')
.replace('Low Humid', 'Limits')
.replace('Power Lost', 'Tech')
.replace('no Supply', 'Tech') for sub in current_list]
print (fc.count("Tech"))
print (fc.count("Limits"))
all_tech = ['Power Lost', 'Failure', 'no Supply']
all_limit = ['High Temp', 'Low Humid']
current_list = ['High Temp', 'Low Humid', 'Power Lost', 'no Supply']
for item in current_list:
if item in all_limit:
current_list.remove('High Temp')
current_list.remove('Low Humid')
current_list.insert(0, 'Limit')
current_list.insert(1, 'Limit')
if item in all_tech:
current_list.remove('Power Lost')
current_list.remove('no Supply')
current_list.insert(0, 'Tech')
current_list.insert(2, 'Tech')
print(current_list)
print(current_list.count('Tech'))
print(current_list.count('Limit'))
I hope this helps, let me know if this is or isn't what you are looking for.