it is sometimes tempting to change list while you are looping over ithoweverit is often simpler and safer to create new list instead import math raw_data [ float('nan') float('nan') filtered_data [for value in raw_dataif not math isnan(value)filtered_data append(valuefiltered_data [ more on conditions the conditions used in while and if statements can contain any operatorsnot just comparisons the comparison operators in and not in check whether value occurs (does not occurin sequence the operators is and is not compare whether two objects are really the same objectthis only matters for mutable objects like lists all comparison operators have the same prioritywhich is lower than that of all numerical operators comparisons can be chained for examplea = tests whether is less than and moreover equals comparisons may be combined using the boolean operators and and orand the outcome of comparison (or of any other boolean expressionmay be negated with not these have lower priorities than comparison operatorsbetween themnot has the highest priority and or the lowestso that and not or is equivalent to ( and (not )or as alwaysparentheses can be used to express the desired composition the boolean operators and and or are so-called short-circuit operatorstheir arguments are evaluated from left to rightand evaluation stops as soon as the outcome is determined for exampleif and are true but is falsea and and does not evaluate the expression when used as general value and not as booleanthe return value of short-circuit operator is the last evaluated argument it is possible to assign the result of comparison or other boolean expression to variable for examplestring string string '''trondheim''hammer dancenon_null string or string or string non_null 'trondheimnote that in pythonunlike cassignment cannot occur inside expressions programmers may grumble about thisbut it avoids common class of problems encountered in programstyping in an expression when =was intended comparing sequences and other types sequence objects may be compared to other objects with the same sequence type the comparison uses lexicographical orderingfirst the first two items are comparedand if they differ this determines the outcome of the comparisonif they are equalthe next two items are comparedand so onuntil either sequence is exhausted if two items to be compared are themselves sequences of the same typethe lexicographical comparison is carried out recursively if all items of two sequences compare equalthe sequences are considered equal if one sequence is an initial sub-sequence of the otherthe shorter sequence is the smaller (lesser data structures