映射对象数组的长度

时间:2017-08-02 13:24:51

标签: python-3.x dictionary

我正在尝试将下面的行转换为python3格式,因为它只与python2兼容。以下代码来自:http://nadbordrozd.github.io/blog/2016/05/20/text-classification-with-word2vec/

res.json({
    items: cart.generateArray(),
    totalPrice: cart.totalPrice
});

搜索后我发现python3中的等价物是

override fun onDataChange(dataSnapshot: DataSnapshot) {

            // Get Post object and use the values to update the UI
            val match = dataSnapshot.children
            var keysArray = KeysHandler()
            if(match!=null){
            // saving keys into an array
                for (data in match){
                    keysArray.addToList(data.key)
                }

            // saving an OnlineMatch object into another array
               repeat(keysArray.list.size){ i->
                   val onlineMatch = dataSnapshot.child(keysArray.getElement(i)).getValue(OnlineMatch::class.java)!!
                   requestsUsers.add(onlineMatch)

               }

                // updating GUI
                updateRequests()
            }

        }

但是,当调用下面的类时,它会出错:self.dim = len(word2vec.itervalues().next())
我似乎无法获得映射对象数组的长度。转换上述行的正确方法是什么?

len(next(iter(word2vec.values())))

0 个答案:

没有答案