I want to remove all <start> and <end> from a dictionary as:
my_dict = {1:['<start> the woman is slicing onions <end>',
'<start> a woman slices a piece of onion with a knife <end>',
'<start> a woman is chopping an onion <end>',
'<start> a woman is slicing an onion <end>',
'<start> a woman is chopping onions <end>',
'<start> a woman is slicing onions <end>',
'<start> a girl is cutting an onion <end>'],
2: ['<start> a large cat is watching and sniffing a spider <end>',
'<start> a cat sniffs a bug <end>',
'<start> a cat is sniffing a bug <end>',
'<start> a cat is intently watching an insect crawl across the floor <end>',,
'<start> the cat checked out the bug on the ground <end>',
'<start> the cat is watching a bug <end>',
'<start> a cat is looking at an insect <end>']
3:['<start> a man is playing a ukulele <end>',
'<start> a man is playing a guitar <end>',
'<start> a person is playing a guitar <end>',]}
>Solution :
try:
my_dict = {k : [s.replace("<start>", "").replace("<end>", "") for s in l] for k, l in my_dict.items() }
You may want to add a strip() after the second replace to get rid of the whitespace.