python script to generate a list shows true for all elements that are not null
Here's a Python script that generates a list and returns a new list with True for all elements that are not null:
original_list = [1, 2, None, 4, None, 6, 7, None, 9]
new_list = [True if element is not None else False for element in original_list]
print(new_list)
Output:
[True, True, False, True, False, True, True, False, True]
In this script, original_list is the list we want to check for null values. We use a list comprehension to loop through each element in the list and check if it's None. If the element is not None, we append True to the new_list. If the element is None, we append False. The resulting new_list contains True for all elements that are not null
原文地址: https://www.cveoy.top/t/topic/eClv 著作权归作者所有。请勿转载和采集!