Python Forum
Filter out all words that begin with P, B, or T.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Filter out all words that begin with P, B, or T.
#4
Alternatively:

import re
colors = ["Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet", "Purple", "Pink", "Brown", "Teal", "Turquois", "Peach", "Beige"]
filtered_colors = list(filter(re.compile('[^PBT]').match, colors))
print(filtered_colors)
Output:
['Red', 'Orange', 'Yellow', 'Green', 'Indigo', 'Violet']
Reply


Messages In This Thread
RE: Filter out all words that begin with P, B, or T. - by michalmonday - May-07-2019, 02:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how to write a code for term that can't begin or end with a stopword desul 3 3,948 Mar-18-2017, 03:42 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020