Every line of 'reverse string in python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
15 def reverse_str(string): 16 rev_list=[] 17 new_list=list(string) 18 while new_list: 19 rev_list += new_list[-1] 20 new_list.pop() 21 return ''.join(rev_list)
30 def reverse(string): 31 n = len(string) 32 33 # Create a empty stack 34 stack = createStack() 35 36 # Push all characters of string to stack 37 for i in range(0,n,1): 38 push(stack,string[i]) 39 40 # Making the string empty since all 41 #characters are saved in stack 42 string="" 43 44 # Pop all characters of string and 45 # put them back to string 46 for i in range(0,n,1): 47 string+=pop(stack) 48 49 return string
1416 @staticmethod 1417 def reverse_string_(s): 1418 """'abc' --> 'cba'""" 1419 return ''.join(reversed(list(s)))
812 def test_returns_original_string_if_unreversible(self): 813 self.assertEqual(reverse(''), '') 814 self.assertEqual(reverse('x'), 'x') 815 self.assertEqual(reverse('!!!'), '!!!')