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

15th Jul 2016, 6:38 AM
hacker charlo
hacker charlo - avatar
7 ответов
+ 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.
15th Jul 2016, 12:06 PM
Tuukka Yildirim
Tuukka Yildirim - avatar
+ 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
15th Jul 2016, 5:13 PM
Sathyanarayana Hadadi
Sathyanarayana Hadadi - avatar
+ 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
15th Jul 2016, 11:31 AM
Tuukka Yildirim
Tuukka Yildirim - avatar
+ 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).
17th Jul 2016, 10:23 PM
Tuukka Yildirim
Tuukka Yildirim - avatar
0
Thanks tuukka and how do I assign the function the data to be manipulated
15th Jul 2016, 11:57 AM
hacker charlo
hacker charlo - avatar
0
Thanks lemme try
15th Jul 2016, 1:29 PM
hacker charlo
hacker charlo - avatar
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
17th Jul 2016, 9:57 PM
hacker charlo
hacker charlo - avatar