How would I write the following more concisely?
genres = ','.join([item for item in list((sheet.cell(n,18).value,
sheet.cell(n,19).value, sheet.cell(n,20).value)) if item])
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.
The
(sheet.cell(n, i).value for i in (18, 19, 20))is a generator expression replacing thelist(…)part. You may replace the tuple(18, 19, 20)with a range or something else.The
filter(None, iterable)is equivalent to(x for x in iterable if x). (In Python 2.x you may want to use itertools.ifilter instead.)Note also that, you can create a list using
instead of the longer
list((sheet.cell(n,18).value, …)).