python loop through list if not empty