I have the code as follows.
for item in my_list:
print(item[0])
temp = []
current_index = my_list.index(item)
garbage_list = creategarbageterms(item[0])
for ele in my_list:
if my_list.index(ele) != current_index:
for garbage_word in garbage_list:
if garbage_word in ele:
print("concepts: ", item, ele)
temp.append(ele)
print(temp)
Now I want to remove ele
from mylist
when it is added to temp
(so that it will not be processed in the main loop, since this is a garbage word).
I know that it is bad to remove items from a list when it is in a loop. So I am wondering if there is an effective way to do this?
For example, if mylist
it looks like this:
mylist = [["tim_tam", 879.3000000000001], ["yummy_tim_tam", 315.0], ["pudding", 298.2],
["chocolate_pudding", 218.4], ["biscuits", 178.20000000000002], ["berry_tim_tam", 171.9],
["tiramusu", 158.4], ["ice_cream", 141.6], ["vanilla_ice_cream", 122.39999999999999]]
1st iteration
for the first element tim_tam
, I get garbage words like yummy_tim_tam
and berry_tim_tam
. Therefore, they will be added to my list temp
.
yummy_tim_tam
berry_tim_tam
( temp
), .
, yummy_tim_tam
, pudding
. pudding
, chocolate_pudding
, biscuits
, tiramu
. , temp
.
3-
ice_cream
. .
, .
["tim_tam", 879.3000000000001], ["yummy_tim_tam", 315.0], ["berry_tim_tam", 171.9] , ["pudding", 298.2]
["chocolate_pudding", 218.4], ["biscuits", 178.20000000000002], ["tiramusu", 158.4]
["ice_cream", 141.6], ["vanilla_ice_cream", 122.39999999999999]