I would use a list comprehension:
def by_size(words, size):
return [word for word in words if len(word) == size]
More Related Contents:
- Unable to use convert strings into integers for a for loop
- Why is it string.join(list) instead of list.join(string)?
- How do I concatenate items in a list to a single string?
- How to check if a string is a substring of items in a list of strings?
- Split a string by a delimiter in python
- What exactly does the .join() method do?
- Create nice column output in python
- Join a list of items with different types as string in Python
- How do I check if there are duplicates in a flat list?
- Pandas DataFrame stored list as string: How to convert back to list
- Check if string ends with one of the strings from a list
- String to list in Python
- How can I convert each item in the list to string, for the purpose of joining them? [duplicate]
- Removing a list of characters in string
- case-insensitive list sorting, without lowercasing the result?
- How does the max() function work on list of strings in python?
- str.startswith with a list of strings to test for
- How to split strings inside a list by whitespace characters
- Splitting List That Contains Strings and Integers
- Replace special characters in a string in Python
- Why python’s list slicing doesn’t produce index out of bound error? [duplicate]
- Converting a string that represents a list, into an actual list object
- Python: find closest string (from a list) to another string
- convert a string which is a list into a proper list python
- How to concatenate (join) items in a list to a single string
- How to convert a string with comma-delimited items to a list in Python?
- Adding a string to a list using augmented assignment
- Column of lists, convert list to string as a new column
- Deleting consonants from a string in Python
- How does str(list) work?