-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_functions.py
More file actions
55 lines (43 loc) · 1.58 KB
/
list_functions.py
File metadata and controls
55 lines (43 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
Author : Ashutosh Kumar
PRN : 19030142009
Assignment - To read a function name from the user and if the function is present for the list then perform that function
on the list else print no such function exists
"""
userinput = ""
l = [1, 2, 3, 4]
try:
userinput = input("Enter a function of list")
if hasattr(list, userinput):
if userinput == 'insert':
position = input("Enter index at which you want to enter")
val = input("Enter value to be Inserted ")
executionOf = "l." + userinput + "(" + position + "," + val + ")"
eval(executionOf)
execution = "l." + userinput + "()"
print(execution)
eval(execution)
else:
print("No such function for list")
except TypeError as e:
listOfMessage = str(e).split()
if listOfMessage[4] == '1':
print("User Function %s" % userinput)
value = input("Enter the value for to perform Function")
new_Str = "l." + userinput + "(" + value + ")"
print(eval(new_Str))
if listOfMessage[3] == "one":
if listOfMessage[0] == "extend()":
count = int(input("Enter how many value You want to extend"))
p = []
for i in range(count):
value = input("Enter new list value no %d" % i)
p.append(value)
l.extend(p)
else:
print("User Function %s" % userinput)
value = input("Enter the value for to perform Function")
new_Str = "l." + userinput + "(" + value + ")"
eval(new_Str)
finally:
print(l)