0
Guys please help me with these (assignment) : -create a function "manipulate_data" that does the following; 1.accepts as the first parameter astring specifying the data structure to be used e. g a list. 2.accepts as the second parameter the data to be manipulated based on the data structure specified e.g [1,4,9,16,25] for alist data structure.
And how will this be without reversing the list only task 1 and 2. Please help I need to understand the assignment in and out. Thanks
7 Respuestas
+ 2
In case you want the effects to stay on the list, try something like this:
def manipulate_data(structure, data):
temp = []
for item in data[::-1]:
temp.append(item)
for i in range(len(data)):
data[i] = temp[i]
Now when calling the manipulate_data with the list you pass as an argument, will be modified if its length is over 0.
+ 2
def manibulateData(type,*args):
if type == "list":
lst = []
for i in args:
lst.append(i)
return lst[::-1]
listData = manibulateData ("list",5,6,7,8)
print(listData )
add for other type
+ 1
Didn't fully understand the question, but something like this?
def manipulate_data(structure, data):
if structure == "list":
return data[::-1] # Return a reversed list
+ 1
well I tested my manipulate_data() as follows:
lst = [1,2,3]
manipulate_data("list", lst)
print(lst) # --> [3,2,1]
Actually my second implementation has an parameter which has no use but has to be filled in (structure).
0
Thanks tuukka and how do I assign the function the data to be manipulated
0
Thanks lemme try
0
Hello guys tuukka tried your program seems its missing something small coz when I run it in IDLE its runs with no errors but displays nothing more like its missing something small