-
Notifications
You must be signed in to change notification settings - Fork 0
/
Reverse_Arry.py
61 lines (48 loc) · 1.21 KB
/
Reverse_Arry.py
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
56
57
58
59
60
61
######################################### For Numbers Only #########################################
def reverseNumber(s):
en = -1
for st, _ in enumerate(range(int(len(s)/2))):
s[st],s[en] = s[en],s[st]
en -= 1
print(s)
######################################### For Strings Only #########################################
def reverseWord(s):
j = -1
k = ""
for _ in range(len(s)-1):
k += s[j]
j -= 1
k += s[-len(s)]
print(k)
def reverse(s):
str = ""
for i in s:
str = i + str
print(str)
def reverseString(string):
string = "".join(reversed(string))
print(string)
def reverse_list(s):
temp_list = list(s)
temp_list.reverse()
final = ''.join(temp_list)
print(final)
def reverse_recursion(s):
if len(s) == 0:
return s
else:
return reverse_recursion(s[1:]) + s[0]
######################################### Generic for Both #########################################
def reverseList(A):
print( A[::-1])
i = [1,2,3,4,5]
k = [6,7,8,9,10]
j = "Dhrumil"
reverseNumber(i)
reverseWord(j)
reverseList(k)
reverseList(j)
reverse(j)
reverseString(j)
reverse_list(j)
print(reverse_recursion(j))