# Wildcard, number of characters (arcpy) [closed]

Is there any way to create a list based on the number of characters of the files? My current list goes like that

`````` rasterList  = arcpy.ListRasters("*speed*","TIF")
``````

My files are speed01 speed02 ..... speed01500

I want for example only speed01000 to speed 01500 If I could apply a wild card with 10 number of characters this would be solved easily

• This sounds like pure Python so I think you should research/ask your question at Stack Overflow.
– PolyGeo
Commented Jul 28, 2018 at 13:31

You can solve this with list comprehension and the len function:

``````speed = ['speed01','speed02','speed01000','speed01500']
speed = [i for i in speed if len(i)==10]
``````

Result:

``````>>speed
['speed01000', 'speed01500']
``````

There are other ways to divide the list, for example see: How do you split a list into evenly sized chunks?:

``````numbers = [i for i in range(10)] #Create some data
numbers
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
chunksize = 4 #Change
numbers = [numbers[i:i + chunksize] for i in xrange(0,len(numbers),chunksize)] #Change xrange to range for python3/ArcGIS Pro

numbers
[[0, 1, 2, 3], [4, 5, 6, 7], [8, 9]]
for g in numbers:
print g

[0, 1, 2, 3]
[4, 5, 6, 7]
[8, 9]
``````
• Thank you. The problem here is that the listRasters list cant hold more than 1000 files. So initially I cannot have a list for all my files. My problem is how to split those 1500 rasters in 1000 and 500.
– GeoF
Commented Jul 28, 2018 at 14:18
• @GeoF why cant it hold more? Do you get an error message?
– Bera
Commented Jul 28, 2018 at 14:35
• No but when I print the list only the first 1000 show up. I think 1000 is the limit in arcpy listRasters function
– GeoF
Commented Jul 28, 2018 at 14:45
• Maybe it is not printing all of them. Try `print len(speed)`, what is the output?
– Bera
Commented Jul 28, 2018 at 14:46
• Hmm that seems to work. Strange but thanks a lot. Maybe they are not all printed. But either way I need to call cellstatistics function afterwards which I think has a limit of 1000 rasters. Am I correct? If thats the case I will try to use list comprehension as you suggested to divide my list
– GeoF
Commented Jul 28, 2018 at 14:59