Skip to content

Instantly share code, notes, and snippets.

@zs1621
Created January 19, 2014 16:57
Show Gist options
  • Save zs1621/8507524 to your computer and use it in GitHub Desktop.
Save zs1621/8507524 to your computer and use it in GitHub Desktop.
python 全局變量錯誤
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#
# Author : Rhapsodyzs
# E-mail : zs1213yh@gmail.com
# Date : 14/01/20 00:42:52
# Desc : 全局變量錯誤
#
c = [(1,2), (2, 3), (3, 4)]
a = []
b = {} # 將此放在循環外
for i in c:
b = {} #將此語句放入循環內部
b['user'] = i[0]
b['dd'] = i[1]
a.append(b)
print a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment