Need some help with Python syntax
Pesudo code
if param is not None in params, param replace(‘xx’, ‘x’)
I get this far:
param.replace('|', '/') for param in ("bar|one","bar|two")
My question is how to add a None check in this line of code?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Perhaps:
Or maybe a tiny bit more legible if we switch the logic around just a bit:
I like the second version a little better because if breaks up the
None else Nonenonsense that was present in the first one…This differs slightly from the (initial) answer by @Tim Pietzcker. His (initial) answer will filter
Nonevalues out of the input iterable whereas this answer will pass them through.Here we use the python conditional expression (which is sometimes known as the “ternary operator” in other languages). The syntax is: