Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8676755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:16:39+00:00 2026-06-12T20:16:39+00:00

I have a list of files names: names = [‘aet2000′,’ppt2000’, ‘aet2001’, ‘ppt2001’] While I

  • 0

I have a list of files names:

names = ['aet2000','ppt2000', 'aet2001', 'ppt2001']

While I have found some functions that can work to grep character strings, I haven’t figured out how to grep all elements of a list.

for instance I would like to:

grep(names,'aet')

and get:

['aet2000','aet2001']

Sure its not too hard, but I am new to Python


update
The question above apparently wasn’t accurate enough. All the answers below work for the example but not for my actual data. Here is my code to make the list of file names:

years = range(2000,2011)
months = ["jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"]
variables = ["cwd","ppt","aet","pet","tmn","tmx"]     #  *variable name*  with wildcards   
tifnames = list(range(0,(len(years)*len(months)*len(variables)+1)  ))
i = 0
for variable in variables:
   for year in years:
      for month in months:
         fullname = str(variable)+str(year)+str(month)+".tif"
         tifnames[i] = fullname
         i = i+1 

Running filter(lambda x:’aet’ in x,tifnames) or the other answers return:

Traceback (most recent call last):
  File "<pyshell#89>", line 1, in <module>
    func(tifnames,'aet')
  File "<pyshell#88>", line 2, in func
    return [i for i in l if s in i]
TypeError: argument of type 'int' is not iterable

Despite the fact that tifnames is a list of character strings:

type(tifnames[1])
<type 'str'>

Do you guys see what’s going on here? Thanks again!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:16:40+00:00Added an answer on June 12, 2026 at 8:16 pm

    Use filter():

    >>> names = ['aet2000','ppt2000', 'aet2001', 'ppt2001']
    >>> filter(lambda x:'aet' in x, names)
    ['aet2000', 'aet2001']
    

    with regex:

    >>> import re
    >>> filter(lambda x: re.search(r'aet', x), names)
    ['aet2000', 'aet2001']
    

    In Python 3 filter returns an iterator, hence to get a list call list() on it.

    >>> list(filter(lambda x:'aet' in x, names))
    ['aet2000', 'aet2001']
    

    else use list-comprehension(it will work in both Python 2 and 3:

    >>> [name for name in names if 'aet' in name]
    ['aet2000', 'aet2001']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .txt file that contains a list of names and some numbers.
I have a list of files with numeric file names (e.g. #.php, ##.php or
I have text files that have list of thousands of names like this DallasWebJobs
I have a list of files, the names of these files are are made
I have list of files with file names with format as ttttyyyymmdd.txt i.e 4
I have a list of files. I also have a list of names which
I have a space delimited list of files names, where spaces in the file
I have .cpp file (text).I want to get the list of all files names
I have a list of file names of files i need to delete. Is
I have a string list of files and a date as their names (separators

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.