-2

I have a list of patterns :

['transcript/123', 'transcript/127', 'transcript/344', 'transcript/346', 'transcript/245', 'transcript/129', ]

I need to loop over all the patterns and look if those patterns match with key names of a dict :

defaultdict(<type 'list'>, {'transcript/129 full_length_coverage=3;length=1108': ['ATTATATATAAAGATTAAAAGTATTACATTTTT'], 'transcript/344 full_length_coverage=2;length=1652': ['CAAGGGAAAGAAAGATAAAAAGTCC'], 'transcript/764 full_length_coverage=19;length=1388': ['CGACGCTTT'], 'transcript/67 full_length_coverage=5;length=1411': ['GAAGATATTTATTATAGGCTTATTAAAGAATATTTT']})

I need to remove items of the dict if the patterns of the list match with the keys of the defaultdict.

I'd like something like that :

for i in my_list:
    for key in my_dict:
         l=key.split(' ')
             if i in key[0]:
                 my_dict.pop(key)

Thanks

Paillou
  • 779
  • 7
  • 16
  • Please go through the [intro tour](https://stackoverflow.com/tour), the [help center](https://stackoverflow.com/help) and [how to ask a good question](https://stackoverflow.com/help/how-to-ask) to see how this site works and to help you improve your current and future questions, which can help you get better answers. "Show me how to write this code" is off-topic for Stack Overflow. You have to make an honest attempt at the solution, and then ask a *specific* question about your implementation. Stack Overflow is not intended to replace existing tutorials and documentation. – Prune Apr 02 '21 at 14:59
  • Your wording suggests that you need to repeat a tutorial on lists, to learn how to search a list and remove an element. – Prune Apr 02 '21 at 15:00

1 Answers1

0

I think you can just go

for i in my_list:
    for key in my_dict:
         if i in key:
             del my_dict[key]


fthomson
  • 773
  • 3
  • 9