Skip to content

Instantly share code, notes, and snippets.

@aodag
Created December 20, 2014 06:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aodag/f0b43ee14cc571c769f3 to your computer and use it in GitHub Desktop.
Save aodag/f0b43ee14cc571c769f3 to your computer and use it in GitHub Desktop.

リストたちを入れる箱を作る

>>> values = {}

いろんな名前で空のリストを作る >>> varname = ('t1', 't2', 't3') >>> for vn in varname: ... values[vn] = [] ...

作った中身

>>> values {'t2': [], 't3': [], 't1': []}

t1のリストを確認

>>> values['t1'] []

空です

t1のリストに値を追加 >>> values['t1'].append(1) >>> values['t1'] [1]

リストたちを確認

>>> values {'t2': [], 't3': [], 't1': [1]}

>>> values['t1'] = [] >>> values['t1'] [] >>> values['t1'].append('a') >>> values['t2'].append('b') >>> values['t3'].append('c') >>> values {'t2': ['b'], 't3': ['c'], 't1': ['a']} >>> values.keys() ['t2', 't3', 't1'] >>> for vn in sorted(values): ... print "{} = {}".format(vn, values[vn]) ... t1 = ['a'] t2 = ['b'] t3 = ['c']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment