Urgent guru help need please



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 items `"ANDELA"`, `"TIA"` and `"AFRICA"` to the set and return the resulting set
return the keys of a dictionary.

so far: this what i have done, please some-one help me in correction
def manipulate_data(item, fruits):
if item == ["apples", "oranges", "mangoes", "grapes"]:
for fruits in reversed(item):
return fruits
elif item == {"apples", "oranges", "mangoes", "grapes"}:
item.append("ANDELA", "TIA", "AFRICA")
return item
if item == {"apples": 23, "oranges": 15, "mangoes": 3, "grapes": 45}:
return dict.keys(fruits)

Creating multiple functions in the same code in Python

You've got a pretty strong vibe of "do my homework" going on here, and what's up with "urgent"?. There isn't even a question, just a copy of your assignment.

There's nothing wrong about asking questions for homework. But do it in a way that allows you to do the assignment by yourself. That goes for non-homework as well.


pls can u give me guidiance in attempting the question.pleassssssss


The first parameter will be a string, the second an object of the data structure indicated in the string:

my_list = ["apples", "oranges", "mangoes", "grapes"]
my_set = {"apples", "oranges", "mangoes", "grapes"}
my_dict =  {"apples": 23, "oranges": 15, "mangoes": 3, "grapes": 45}

def manipulate(structure, object):
    if structure == "list":
        return reversed(object)                         # this line is wrong
    elif structure == "set":
        return object.append("ANDELA", "TIA", "AFRICA") # this line is wrong
    elif structure == "dictionary":
        return object.keys()

manipulate("list", my_list)
manipulate("set", my_set)
manipulate("dictionary", my_dict)

This better not be the exact answer or I'll be ticked, since I've essentially done your homework for you. It is meant as a demonstration of how the instructions are to be followed.

You'll need to study up on how to correct the lines that are wrong.



i think u didnt read the question very well


So clearly the function must start like this:

def manipulate_data(kind, data):

and have some kind of decision inside the function, based on the first
parameter, which will be one of the strings "list", "set" or "dictionary".

So the function might be called in these ways:

manipulate_data("list", ["apples", "orange", "mangoes"])

manipulate_data("set", {"apples", "orange", "mangoes"})

manipulate_data("dictionary", {"apples": 23, "oranges": 15, "mangoes": 3, "grapes": 45})

but my challange is this:
elif kind == 'set':
... do stuff with data using it as a set ...
... add items "ANDELA", "TIA" and "AFRICA" to the set ...
... and return the resulting set ...
how do i make data a set and add those items to it?
here is my function and parameters:
def manipulate_data(kind, data):


please help!!!! @ corner bar


I think you didn't read the page that I linked to. It explains everything well enough. I completed the challenge with just that information.



It also does not help that there are several topics still current about this exercise. I had a post several days ago about it too. Post

I like the if/elif statements of your code but I have learned that when you are type checking or just checking things in general it is better to add scalability to it when you program it. I also have an example of it in the post I linked.


While it may be slightly outside the context of these exercises it is valuable to keep in mind that you should always program in a way that makes it easier for you.

Also, the frozen sets are cool, you can also used namedtuples too that is another cool little module.

Example: Named Tuples

from collections import namedtuple

vectors = namedtuple('Vectors', 'X Y Z')
v = vectors(5, 1, 2)
for vec in v:
# Or
print(v[0], v[1], v[2])

They are sweet little things that you can do all types of things with. Again, a little out of the scope of these classes.


Excellent example! Makes perfect sense. Thank you.


Can we please stop giving this person code to use? Or any others asking about this for that matter. Do a google search on what's asked here, it's not the only place this has been asked about in the same poor manner, by the same person even, in the last few days, and they have been told how to better conduct themselves in ways I agree with but would get my fingers slapped for by expressing myself that way.

If this person wants help then they have received plenty of information in duplicate about how to to ask questions and they would get immediate answers if only they took that advice.

If for any reason it's unclear what is causing this reaction, please read through http://www.catb.org/esr/faqs/smart-questions.html