Remove empty items from lookupRecords list

Mostly wondering if there is a simpler / more direct / elegant way of removing empty records from a lookupRecords list. Here’s what I’m using:

statuses = []
records = Laptops.lookupRecords(refName=$id).status
for record_item in records:
  if record_item == '':
    pass
  else:
    statuses.append(record_item)
return statuses

Looking forward to seeing what else I could’ve done.

Thanks for looking.

[status for status in Laptops.lookupRecords(refName=$id).status if status]
2 Likes

Nice! I need to learn more about how you structured that. I get that the [ ] puts the results into an array. The status for is what I’m not sure about. Is it the equivalent of status = ?

It’s called a list comprehension.

3 Likes