Games software
Video games
Music games
Fighting games
Mapping games
Sports games
Travelling games
Spy games
Board games
Educational games
Simulation games
Role-playing games
Simulation games
Other games
Multiplayer games
External links
Category:2010 video games
Category:Split-screen multiplayer games
Category:Video games developed in the United States
Category:Video games set in the United States
Category:Windows games
Category:Windows-only games
Category:Xbox 360 games
Category:Xbox 360 Live Arcade gamesQ:
Python3 - list comprehension alternative
Here's my function.
def extract(x):
r = x.strip().split()
return [y for y in r if '|' in y]
I want to convert it to a list comprehension to shorten the code, but I can't get it to work.
Any help would be appreciated.
A:
In your case, you can just use str.strip:
def extract(x):
return [y for y in x.strip().split('|') if y]
Or even more simply:
def extract(x):
return [y.strip('|') for y in x.split('|')]
The only downside of the second approach is that it will remove characters from both sides of the delimiter, while in the first approach, only the rightmost one is removed.
And if you use the first approach, you can even drop the strips altogether, since:
>>> '|'.join(x.split('|'))
'|'.join(x)
Will do the same thing.
As a part of it, Iran has opened its first ever aircraft repair base at Imam Khomeini International Airport, which will be overseen by the Industry, Mines and Trade (IMT) Ministry of Iran. The move to repair foreign planes is part of Iran’s efforts to diversify its fuel supplies after years of relying on Russian and Chinese planes.
During the second half of August, Iran will train a team of 11 engineers in the repair of Lockheed C-130 Hercules aircraft, and the first batch of the two planes will arrive in the country next month. The mission will also include the ac619d1d87
Related links:
Comments