Menu

gitpiper

words python Code Snippet in 2024

stringregexpbeginner

Last Updated: 22 April 2024

Converts a given string into a list of words.

  • Use re.findall() with the supplied pattern to find all matching substrings.
  • Omit the second argument to use the default regexp, which matches alphanumeric and hyphens.
import re def words(s, pattern = '[a-zA-Z-]+'): return re.findall(pattern, s)
words('I love Python!!') # ['I', 'love', 'Python'] words('python, javaScript & coffee') # ['python', 'javaScript', 'coffee'] words('build -q --out one-item', r'\b[a-zA-Z-]+\b') # ['build', 'q', 'out', 'one-item']

python snippet similar to words For You in April 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️