One Line 'If' or 'For'...
Posted
by aTory
on Stack Overflow
See other posts from Stack Overflow
or by aTory
Published on 2009-11-13T12:47:59Z
Indexed on
2010/05/09
5:28 UTC
Read the original article
Hit count: 366
Every so often on here I see someone's code and what looks to be a 'one-liner', that being a one line statement that performs in the standard way a traditional 'if' statement or 'for' loop works.
I've googled around and can't really find what kind of ones you can perform? Can anyone advise and preferably give some examples?
For example, could I do this in one line:
example = "example"
if "exam" in example:
print "yes!"
Or:
for a in someList:
list.append(splitColon.split(a))
© Stack Overflow or respective owner