From 279c727ea02c5c2004ca35985c5509524ddf059c Mon Sep 17 00:00:00 2001 From: surister Date: Tue, 22 Oct 2019 09:19:57 +0200 Subject: [PATCH] add Python begginner reverse a string answer --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2af2d93..d152ea3 100644 --- a/README.md +++ b/README.md @@ -1751,8 +1751,14 @@ set([food for bro in x for food in bro['food']])
How to reverse a string?
-Shortest way is: my_string[::-1] but it doesn't mean it's the most efficient one. -
+Shortest way is: my_string[::-1] but it doesn't mean it's the most efficient one.
+Cassic way is: +def reverse_string(string): + temp = "" + for char in string: + temp = char + temp + return temp +
Write a function to determine if a given string is a palindrome