有人请看看我的Python语法? [英] Someone please take a look at my Python syntax?

查看:160
本文介绍了有人请看看我的Python语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以向我解释我的代码中缺少什么?我一直在看互联网上的解决方案,我发现一个模板,我认为是正确的,但仍然给我错误。任何人知道我在做错什么?



  • 创建一个函数manipulate_data,执行以下操作: / p>


  • 接受第一个参数,指定要使用的数据结构的列表list,set或dictionary。
    根据列表数据结构指定的数据结构(例如[1,4,9,16,25]),接受作为第二个参数的操作数据。


  • 根据第一个参数返回列表的相反,或者添加项目ANDELATIA 非洲到该集合,或将结果集返回到字典的键。





  def manipulate_data(kind,data):
if kind ==列表:
[1,4,9,16,25]中的数据:
return data.reverse()

elif kind ==set:

data.add(TIA)
data.add(ANDELA)
data.add )
data.add(AFRICA)
返回数据

elif kind ==dictionary:
用于{nissan中的数据:23, audi:15,mercedes:3,volvo:45}:
return data.key()


解决方案

根据问题,这个函数只需要2个参数:

 $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $如果data_type = ='set':
return set.union(data,[ANDELA,TIA,AFRICA])
如果data_type =='dict':
return [ key,item.items()]


Can someone please explain to me what is missing in my code? I have been looking at solutions on the internet and I found a template that I thought would be correct but its still giving me errors. Anyone know what I am doing wrong?

  • Create a function manipulate_data that does the following:

  • Accepts as the first parameter a string specifying the data structure to be used "list", "set" or "dictionary". Accepts as the second parameter the data to be manipulated based on the data structure specified (e.g [1, 4, 9, 16, 25]) for a list data structure.

  • Based off the first parameter return the reverse of a list, OR add the items "ANDELA", "TIA" and "AFRICA" to the set, or return the resulting set as keys of a dictionary.

def manipulate_data(kind, data):
    if kind == "list":
        for data in [1, 4, 9, 16, 25]:
            return data.reverse()

    elif kind == "set":
        for data in {"f", "g", "h", "i", "j"}:
            data.add("ANDELA")
            data.add("TIA")
            data.add("AFRICA")
            return data

    elif kind == "dictionary":
        for data in  {"nissan": 23, "audi": 15, "mercedes": 3, "volvo": 45}:
            return data.key()

解决方案

This one works according to the question the function only takes in 2 parameters:

def manipulate_data(data_type=None, data=None):
    if data_type is 'list':
        return data[-1::-1]
    if data_type == 'set':
        return set.union(data, ["ANDELA", "TIA", "AFRICA"])
    if data_type == 'dict':
        return [key for key, item in data.items()]

这篇关于有人请看看我的Python语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆