if/else condition in list comprehension

Question:

How do I write both short and long names in a single list comprehension line?

#this is how i tried below code but its not working.
short_names, long_names = [(i,j) for i,j in planet_names if len(i) <= 5  
else len(j) > 5 ]

#working code
planet_names = ["Mercury", "Venus", "Earth", "Mars", "Jupiter","Saturn"]                         
short_names = [i for i in planet_names if len(i) <= 5]
long_names = [i for i in planet_names if len(i) > 5]
Asked By: Sai Kumar

||

Answers:

short_names=[]
long_names=[]
planet_names = ["Mercury", "Venus", "Earth", "Mars", "Jupiter","Saturn"]                         
for i in planet_names :
    if len(i) <= 5:
        short_names.append(i) 
    else:
        long_names.append(i)
Answered By: mad_
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.