Reputation: 3081
Is there a simple way to rewrite this snippet using list comprehension?
f_list = []
for f in file_list:
if os.path.isfile(SC_JSON_DIR + f + ".json"):
f_list.append(f)
return f_list
Upvotes: 0
Views: 233
Reputation: 20336
Try this:
return [f for f in file_list if os.path.isfile(SC_JSON_DIR + f + ".json")]
Upvotes: 8