Skip to content

Instantly share code, notes, and snippets.

@HirofumiYashima
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HirofumiYashima/7ad07268e650112843ea to your computer and use it in GitHub Desktop.
Save HirofumiYashima/7ad07268e650112843ea to your computer and use it in GitHub Desktop.
Python のリスト内包表記に、if ~ だけでなく、else ~ を付ける方法 ref: http://qiita.com/HirofumiYashima/items/0e5fcebd083bae1a78a2
['1%', '7%', 'NULL', '8%', 'na', '']
[x if type(x)!=int else x**2 for x in data_list_2]
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