【问题标题】:An encoding that maps the values of the function to a list将函数的值映射到列表的编码
【发布时间】:2020-03-16 03:59:50
【问题描述】:

我必须创建一个编码函数,它接收列表中的数字并返回以下内容:

  • encode(0) 应该返回 [] 即 0 映射到列表
  • encode(x+1) 应该返回 [encode(x),[encode(x)]] 即 x+1 映射到包含 encode(x) 的列表(即 [encode(x)])和 encode(x)

如果有任何困惑,请告诉我!

【问题讨论】:

  • 你忘了问问题。请访问help center 并阅读How to Ask
  • 请展示你到目前为止所做的尝试。

标签: python python-3.x list function mapping


【解决方案1】:

这个功能和你描述的差不多:

def encode(i):
    if i == 0:
        return []
    else:
        r=encode(i-1)
        return [r,[r]]

【讨论】:

    猜你喜欢
    • 2012-09-27
    • 1970-01-01
    • 2014-02-19
    • 2019-10-12
    • 1970-01-01
    • 1970-01-01
    • 2010-10-04
    • 1970-01-01
    • 2019-02-28
    相关资源
    最近更新 更多