Last active
August 29, 2015 14:14
-
-
Save HirofumiYashima/7ad07268e650112843ea to your computer and use it in GitHub Desktop.
Python のリスト内包表記に、if ~ だけでなく、else ~ を付ける方法 ref: http://qiita.com/HirofumiYashima/items/0e5fcebd083bae1a78a2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
['1%', '7%', 'NULL', '8%', 'na', ''] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[x if type(x)!=int else x**2 for x in data_list_2] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from decimal import Decimal | |
import types | |
data_lit_3 = [0.01, 0.07, 'NULL', 0.08, 'na', ''] | |
['%g%%' % y if type(y)==Decimal else y for y in [Decimal(str(x))*Decimal('100') if type(x)==float else x for x in data_list_3]] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment