首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏Pythonista

    day25 map,filter,reduce 内置函数,作业

    [d]>20,shares)) print(res) ################################################## =====================作业三 #如下,每个小字典的name对应股票名字,shares对应多少股,price对应股票的价格 portfolio = [ {'name': 'IBM', 'shares': 100, 'price ': 91.1}, {'name': 'AAPL', 'shares': 50, 'price': 543.22}, {'name': 'FB', 'shares': 200, 'price ': 21.09}, {'name': 'HPQ', 'shares': 35, 'price': 31.75}, {'name': 'YHOO', 'shares': 45, 'price ': 16.35}, {'name': 'ACME', 'shares': 75, 'price': 115.65} ] 1:map来得出一个包含数字的迭代器,数字指的是:购买每支股票的总价格

    53610发布于 2018-08-31
  • 来自专栏Linux云计算网络

    从一个集合中查找最大最小的N个元素——Python heapq 堆数据结构

    1 >>> portfolio = [ 2 {'name': 'IBM', 'shares': 100, 'price': 91.1}, 3 {'name': 'AAPL', 'shares ': 50, 'price': 543.22}, 4 {'name': 'FB', 'shares': 200, 'price': 21.09}, 5 {'name': 'HPQ', 'shares': 35, 'price': 31.75}, 6 {'name': 'YHOO', 'shares': 45, 'price': 16.35}, 7 {'name' ': 45}, {'price': 21.09, 'name': 'FB', 'shares': 200}, {'price': 31.75, 'name': 'HPQ', 'shares': 35}] ': 50}, {'price': 115.65, 'name': 'ACME', 'shares': 75}, {'price': 91.1, 'name': 'IBM', 'shares': 100

    2.1K100发布于 2018-01-11
  • 来自专栏简说基因

    Python在生物信息学中的应用:同时对数据做转换和换算

    for x in s)) # Data reduction across fields of a data structure portfolio = [ {'name':'GOOG', 'shares ': 50}, {'name':'YHOO', 'shares': 75}, {'name':'AOL', 'shares': 20}, {'name':'SCOX', 'shares ': 65} ] min_shares = min(s['shares'] for s in portfolio) 讨论 上述解决方案展示了当把生成器表达式作为函数的单独参数时在语法上的一些微妙之处,即不必重复使用括号 例如在 portfolio 的例子中,可以使用下面的替代方案: # Original: Returns 20 min_shares = min(s['shares'] for s in portfolio ) # Alternative: Returns {'name': 'AOL', 'shares': 20} min_shares = min(portfolio, key=lambda s: s['shares

    25510编辑于 2024-02-21
  • python练习题-day16

    {'name': 'AAPL', 'shares': 50, 'price': 543.22}, {'name': 'FB', 'shares': 200, 'price': 21.09}, {'name': 'HPQ', 'shares': 35, 'price': 31.75}, {'name': 'YHOO', 'shares': 45, 'price': 16.35}, {' portfolio = [ {'name': 'IBM', 'shares': 100, 'price': 91.1}, {'name': 'AAPL', 'shares': 50, 'price': 543.22}, {'name': 'FB', 'shares': 200, 'price': 21.09}, {'name': 'HPQ', 'shares': 35, 'price': 31.75} , {'name': 'YHOO', 'shares': 45, 'price': 16.35}, {'name': 'ACME', 'shares': 75, 'price': 115.65}] 6.

    52920发布于 2019-10-23
  • 来自专栏葫芦

    python heapq

    ,{'name':'TEN','shares':231,'price':20} ... ,{'name':'FUN','shares':12,'price':58}] >>> cheap = heapq.nsmallest(3,portfolio,key=lambda s:s['price ']) >>> cheap [{'price': 20, 'name': 'TEN', 'shares': 231}, {'price': 32.1, 'name': 'IBM', 'shares': 100}, {'price': 58, 'name': 'FUN', 'shares': 12}] >>> expensive=heapq.nlargest(3,portfolio,key=lambda ', 'shares': 100}, {'price': 20, 'name': 'TEN', 'shares': 231}] >>>

    41920发布于 2019-04-17
  • 基于go使用redis实现简易排行榜功能

    = append(shares, share)}}// 填充空的排行榜排名至十个emptyShare := Share{Id: "虚位以待",ViewCount: 0,}for len( shares) < 10 {shares = append(shares, emptyShare)}// 由于获取排行榜时有可能排行榜的Zset发生变动,需要按照确定的播放数重新排名一次sort.Slice (shares, func(i, j int) bool {return shares[i].ViewCount > shares[j].ViewCount})ctx.JSON(200, shares) shares) < 10 {shares = append(shares, emptyShare)}// 由于获取排行榜时有可能排行榜的Zset发生变动,需要按照确定的播放数重新排名一次sort.Slice (shares, func(i, j int) bool {return shares[i].ViewCount > shares[j].ViewCount})ctx.JSON(200, shares)

    56710编辑于 2024-05-22
  • 来自专栏TechFlow

    EasyC++58,构造函数

    比如我们还是之前的类: class Stock { private: std::string company; long shares; double share_val ; double total_val; void set_tot() {total_val = shares * share_val;} public: void can't be negative;" << company << " shares set to 0. \n"; shares = 0; }else { shares = n; share_val = pr; set_tot(); ) {} 如果一致的话,就会出现这样的代码: shares = shares; 为了避免这种混乱,一般会在代码风格层面加以区分。

    24710编辑于 2022-08-26
  • 来自专栏sktj

    python 类装饰器与元类

    , key, value(key)) return cls return decorate Example @check_attributes(name=SizedString(size=8), shares =UnsignedInteger, price=UnsignedFloat) class Stock: def init(self, name, shares, price): self.name = name self.shares = shares self.price = price 另外一种方式是使用元类: A metaclass that applies checking class = UnsignedInteger() price = UnsignedFloat() def __init__(self, name, shares, price): self.name = name self.shares = shares self.price = price

    1.1K20发布于 2019-12-13
  • 来自专栏院长运维开发

    samba服务安装脚本

    Guest Users,Username for Guest: "tom" #Shared Directories 共享文件 #Share Name: "Share 1" #File Path: "/shares yes map to guest = bad user guest account = tom cups options = raw [Share 1] path = /shares comment = All Printers guest ok = yes EOF # Make sure shared directories exist... mkdir -p /shares if `selinuxenabled` then semanage fcontext -a -t samba_share_t '/shares(/.*)?' restorecon -FRvv /shares fi # Enable and start samba service... systemctl enable smb systemctl start

    1.2K20发布于 2020-09-07
  • 来自专栏AI SPPECH

    037_密码学实战:安全多方计算MPC技术深度解析——从秘密共享到隐私保护计算的完整指南

    = 5 # 生成的总份额数 # 生成份额 shares = generate_shamir_shares(secret, threshold, num_shares) # 生成份额 shares = generate_additive_shares(secret, num_shares) print(f"生成的份额: {shares}") 将三元组分成份额 a_shares = generate_additive_shares(a, num_parties, prime) b_shares = generate_additive_shares y_shares, b_shares)] # 4. z_i = (c_shares[i] + d_b_shares[i] + e_a_shares[i] + de_shares[i]) % prime z_shares.append(z_i

    1.1K10编辑于 2025-11-18
  • 来自专栏Pythonista

    day24,python习题

    i) ----------------------------------------------------------------------------------------------- shares , 'lenovo':27.3, 'huawei':40.3, 'oldboy':3.2, 'ocean':20.1 } 问题一:得出股票价格大于30的股票名字列表 for i in shares : if shares[i] > 30: print (i) ---------------------------------------------------------- -- i=[i for i in shares if shares[i] > 30] print(i) ------------------------------------------------- --------------------- 问题二:求出所有股票的总价格 print((i for i in shares.values())) --------------------------

    53320发布于 2018-08-31
  • 来自专栏FreeBuf

    PowerHuntShares:一款针对活动目录域安全的分析与审计工具

    o Identify shares that provide reads & write access o Identify shares thare are high risk from 49 computers [*][03/01/2021 09:36] - 217 SMB shares were found. [*][03/01/2021 09:36] Getting share permissions from 217 SMB shares [*][03/01/2021 09:37] - 374 share permissions were enumerated ] [*][03/01/2021 09:37] SHARE SUMMARY [*][03/01/2021 09:37] - 217 shares were found. are typically two default shares. [*][03/01/2021 09:37] - 46 (21.20%) shares across 32 systems were

    1.6K30编辑于 2023-02-10
  • 来自专栏sktj

    python nlargest nsmallest

    , 37, 23] print(heapq.nsmallest(3, nums)) # Prints [-4, 1, 2] dict portfolio = [ {'name': 'IBM', 'shares ': 100, 'price': 91.1}, {'name': 'AAPL', 'shares': 50, 'price': 543.22}, {'name': 'FB', 'shares': 200 , 'price': 21.09}, {'name': 'HPQ', 'shares': 35, 'price': 31.75}, {'name': 'YHOO', 'shares': 45, 'price ': 16.35}, {'name': 'ACME', 'shares': 75, 'price': 115.65} ] cheap = heapq.nsmallest(3, portfolio,

    56630发布于 2019-09-25
  • 来自专栏云原生运维社区

    JVM 如何获取当前容器的资源限制?

    is /sys/fs/cgroup/cpu,cpuacct/cpu.shares CPU Shares is: 681 CPU Quota count based on quota/period: 4 CPU Share count based on shares: 1 OSContainer::active_processor_count: 4 Path to /cpu.cfs_quota_us is /sys/fs/cgroup/cpu,cpuacct/cpu.shares CPU Shares is: 681 CPU Quota count based on quota/period: 4 CPU Share count based on shares: 1 OSContainer::active_processor_count: 4 …… java version "1.8.0_191 也可以通过 cpu.shares 来获取: $ cat /sys/fs/cgroup/cpu,cpuacct/cpu.shares 681 不过这个值是 CPU 占用份额,无法根据这个算出来可用 CPU

    1.5K10编辑于 2024-04-11
  • 来自专栏Kubernetes

    docker-monitor-injector源码分析

    user_sum: cpuacct.stat.user system_sum: cpuacct.stat.system nice_sum: (_self*cpu.shares/1024)/sysconf (_SC_NPROCESSORS_ONLN) idle_sum: (_self*cpu.shares/1024)/sysconf(_SC_NPROCESSORS_ONLN) iowait_sum: (_self*cpu.shares/1024)/sysconf(_SC_NPROCESSORS_ONLN) irq_sum: (_self*cpu.shares/1024)/sysconf(_SC_NPROCESSORS_ONLN ) softirq_sum:(_self*cpu.shares/1024)/sysconf(_SC_NPROCESSORS_ONLN) steal_sum: (_self*cpu.shares/1024 )/sysconf(_SC_NPROCESSORS_ONLN) guest_sum: (_self*cpu.shares/1024)/sysconf(_SC_NPROCESSORS_ONLN) 任一

    1.1K90发布于 2018-04-13
  • 来自专栏Reck Zhang

    Ethereum 01 - 保证智能合约的安全可靠

    > uint) shares; // withdraw your share function withdraw() { if(this.balance < shares { shares[msg.sender] = 0; } } } 在这段智能合约中, 有一个mapping类型的变量shares, 和一个withdraw 函数. shares记录着每个用户在Fund中拥有的”股权”, 假定一份Fund的股权等价于一个以太币. [msg.sender] = 0这句话, 而重复地执行msg.sender.call.value(shares[msg.sender])(). => uint) shares; // withdraw your share function withdraw() { uint share = shares[msg.sender

    47210发布于 2021-08-11
  • 来自专栏GopherCoder

    Python 强化训练: 第一篇

    ': 100, 'price': 91.1}, {'name': 'AAPL', 'shares': 50, 'price': 543.22}, {'name': 'FB', 'shares': 200 , 'price': 21.09}, {'name': 'HPQ', 'shares': 35, 'price': 31.75}, {'name': 'YHOO', 'shares': 45, 'price a["shares"]) print(cheap, "\n", expensive) # [{'price': 16.35, 'name': 'YHOO', 'shares': 45}, {'price ': 31.75, 'name': 'HPQ', 'shares': 35}] # [{'price': 543.22, 'name': 'AAPL', 'shares': 50}, {'price' : 21.09, 'name': 'FB', 'shares': 200}] 3.

    78440发布于 2018-06-06
  • 来自专栏Eric杂货铺

    samba服务安装脚本

    Guest Users,Username for Guest: "tom" #Shared Directories 共享文件 #Share Name: "Share 1" #File Path: "/shares passwords = yes map to guest = bad user guest account = tom cups options = raw [Share 1] path = /shares samba comment = All Printers guest ok = yes EOF # Make sure shared directories exist... mkdir -p /shares if `selinuxenabled` then semanage fcontext -a -t samba_share_t '/shares(/.*)?' restorecon -FRvv /shares fi # Enable and start samba service... systemctl enable smb systemctl start

    92210发布于 2020-09-24
  • 来自专栏python与大数据分析

    关于python类中描述器-类型检查、延迟和代理

    applies it to selected attributes # 类型检查的描述器 def typeassert(**kwargs): #{'name': <class 'str'>, 'shares Typed(name, expected_type)) return cls return decorate # 描述器应用样例 @typeassert(name=str, shares =int, price=float) class Stock: def __init__(self, name, shares, price): self.name = name self.shares = shares self.price = price def __str__(self): return 'name= ,{},shares={},price={}'.format(self.name,self.shares,self.price) #延迟计算属性 #将一个只读属性定义成一个property,只在访问的时候才会计算结果

    64920编辑于 2022-03-11
  • 来自专栏python3

    day 16 - 2 内置函数(二)练习

    ()) else: for i in range(5): print(l[(page_num-1)*5+i].strip()) 4、如下,每个小字典的 name 对应股票名字,shares 对应多少股,price 对应一股的价格 portfolio = [ {'name': 'IBM', 'shares': 100, 'price': 91.1}, {'name': 'AAPL ', 'shares': 50, 'price': 543.22}, {'name': 'FB', 'shares': 200, 'price': 21.09}, {'name': 'HPQ ', 'shares': 35, 'price': 31.75}, {'name': 'YHOO', 'shares': 45, 'price': 16.35}, {'name': 'ACME ', 'shares': 75, 'price': 115.65} ]   #4.1、计算购买每支股票的总价 ret = map(lambda dic:{dic['name']:round(dic['shares

    51510发布于 2020-01-20
领券