# Filtering View List by String - Python

**URL:** <https://forum.dynamobim.com/t/filtering-view-list-by-string-python/33662>\
**Category:** Lists-Logic\
**Created:** [March 18, 2019, 7:24pm UTC](https://forum.dynamobim.com/t/filtering-view-list-by-string-python/33662 "2019-03-18T19:24:50Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![cgartland](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/cgartland/32/45378_2.png) [@cgartland](https://forum.dynamobim.com/u/cgartland)\
**Post date:** [March 18, 2019, 8:18pm UTC](https://forum.dynamobim.com/t/filtering-view-list-by-string-python/33662/2 "2019-03-18T20:18:34Z")

</div>

Using the [Element.Name](http://www.revitapidocs.com/2018.1/e372092e-ff47-71c2-1272-50ab08e5a41d.htm) property you can do this quite easily. The following expects `IN[0]` to be a list of elements. You can also greatly reduce the redundancy in your script by defining a custom function:

```
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

def filter_list(elements, search_str):
	"""Given a list of Views, returns only those which
	contain a given string in their name"""
	passed = []
	for element in elements:
		name = element.Name
		if search_str in name:
			passed.append(element)
	return passed

views = [UnwrapElement(view) for view in IN[0] if view is not None]
nwc = filter_list(views, 'NWC')
elec = filter_list(views, 'ELEC')

OUT = nwc, elec

```

[views.dyn](https://forum.dynamobim.com/uploads/short-url/3riACz4vwJGGpgltK9ezI03zTn3.dyn) (5.1 KB)

This could also be easily modified to accept a list of strings to test (e.g. `["NWC", "ARCH", "STRC"...]`) since you’re combining all of the lists anyway.

---

_[View the full topic](https://forum.dynamobim.com/t/filtering-view-list-by-string-python/33662)._
