for k,v in targets.iteritems(): price= str(v['stockprice']) Bids = str(u''.join(v['OtherBids'])) Bids = Bids.split(',') # create a list of unique bids by ranking for a,b in zip(float(price),Bids): try: del b[next(i for i,e in enumerate(b) if format(e,'.4f') == a)] except StopIteration: pass
我从我的字典中提取数据,但似乎所有这些都是unicode.我怎么能摆脱unicode废话?
解决方法
我认为你的代码是给你错误信息,TypeError:zip参数#1必须支持迭代.由于表达式zip(float(price),Bids),您收到此错误.此简化代码演示了错误:
>>> price = str(u'12.3456') >>> bids = ['1.0','2.0'] >>> zip(float(price),bids) Traceback (most recent call last): File "<stdin>",line 1,in <module> TypeError: zip argument #1 must support iteration
Python 2.x zip()
built-in library function要求其所有参数都是可迭代的. float(price)不是可迭代的.
如果要将float(price)与数组Bids的每个元素组合在一起,可以在第一个参数表达式中使用itertools.repeat()
.
>>> import itertools >>> price = str(u'12.3456') >>> bids = ['1.0','2.0'] >>> zip(itertools.repeat(float(price),len(bids)),bids) [(12.345599999999999,'1.0'),(12.345599999999999,'2.0')]
我没有看到你使用Unicode数据类型与TypeError有关.