Is there a shorter way to make this function?

后端 未结 7 988
鱼传尺愫
鱼传尺愫 2021-01-24 23:47

B. front_x Given a list of strings, return a list with the strings in sorted order, except group all the strings that begin with \'x\' first. e.g. [\'mix\', \'xyz\', \'apple\',

7条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-24 23:59

    return sorted([w for w in words if w[0] == 'x']) + sorted([w for w in words if w[0] != 'x'])
    

提交回复
热议问题