【15】python 列表补充+orientdb更新属性值

def supplement_list(list,supplementList,supplementListPos):
    """
    补充列表:将需要补充的信息按位置补充完成
    定义声明位置数值(temp_list_pos)的数值和长度(数值为50+长度和全列表长度相同)
    两个列表对应比较(全列表+补充列表)
    全列表和补充列表中都存在一个数值,位置数值(temp_list_pos)对应的数值取原补充数值
    返回数值:全列表+位置数值列表
    缺点:全列表中与补充列表相同的数值不能重复
    用时:1.185185653406678e-05
    """
    temp_list_pos = [50]*len(list)
    for i in range(len(list)):
        for j in range(len(supplementList)):
            if list[i] == supplementList[j]:
                temp_list_pos[i] = supplementListPos[i]
                break
    return list,temp_list_pos


if __name__ == '__main__':
    list = [1, 2, 3, 4, 5, 4]
    supplementList = [1, 2, 3]
    supplementListPos = ['a', 'b', 'c']
    supplement_list(list, supplementList, supplementListPos)




优化函数(O(n*n)-->O(n))(用时:2.0543217992382415e-05)
获取列表的index可以中遍历的方式,也可以中index的方式
def supplement_list(list_key,supplement_list_key,supplement_list_value):
    temp_list_value = [50]*len(list_key)
    for i in range(len(list_key)):
        if list_key[i] in supplement_list_key:
            b_index=supplement_list_key.index(list_key[i])       #(按数值去找index:少去一个循环)
            temp_list_value[i] = supplement_list_value[b_index]
    return list_key,temp_list_value




update数据库中实体的属性
select @rid from v_patient where name == '7bef992b222aab683113ac2b3163386c64337edaadf4cfd0c853998e098badda'
获取rid之后用update的方法,更新加入新的元素就好
rids = client.command("select @rid from v_patient where name == '7bef992b222aab683113ac2b3163386c64337edaadf4cfd0c853998e098badda'")
    for rid in rids:
        print(rid.rid)
        client.command("UPDATE {} SET gender='female' RETURN AFTER @rid".format(rid.rid))





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值