+ 10

Hi - I'm new at coding. Could someone please help me write a code which gives a mirror output of an in input string?

I have defined the universe as {'b': 'd', 'd' : 'b', 'o': 'o', 'p' : 'q' ....} I have given an input but am unsure how to take it forward to get to the output. Example: if the input is 'vow'; the desired output should be 'wov'. Any help would be appreciated. Thanks

5th Apr 2020, 7:52 AM
Snigdha Datta
Snigdha Datta - avatar
46 Respostas
+ 5
We can only mirror d,b,q,p Here is the code i reckon that you're looking for: dict={'q':'p','p':'q','d':'b','b':'d'} x=input()[::-1] a='' for i in x: if i in dict: i=dict[i] a+=i print(a)
5th Apr 2020, 8:19 AM
Tricker
+ 3
Hi - thanks for the responses but I do not need only reversing of the letters. I need them to be mirrored...i.e. they should also be visually reversed. Example: for a random input of "poiw", the output should be "wioq" Thanks again
5th Apr 2020, 8:07 AM
Snigdha Datta
Snigdha Datta - avatar
+ 3
istr=input() print(istr[::-1]) I think this will give an mirror output of given string
6th Apr 2020, 7:06 AM
Addaganti Naga Sai Rajeev
Addaganti Naga Sai Rajeev - avatar
+ 3
Snigdha Datta As I'm not sure what you exactly want reverse or mirror after reading the suggestions, but question says , "Mirror" : -- old code edited & resaved -- https://code.sololearn.com/cC4CETbktz2J/?ref=app
6th Apr 2020, 12:26 PM
Daljeet Singh
Daljeet Singh - avatar
+ 2
You mean this? x='hello world' print(x[::-1]) #this would print #dlrow olleh
5th Apr 2020, 7:59 AM
Tricker
+ 2
Thanks for all your inputs - this would help me learn some other concepts on python, as well.
6th Apr 2020, 10:00 AM
Snigdha Datta
Snigdha Datta - avatar
+ 2
# first take the user input a = input() # Reverse the list a = a[::-1] # print the list print(a) #Or you could also have used " a = a.reverse()" # Or use " a=' '.join(reversed(a)) "
6th Apr 2020, 2:22 PM
Priyanka
+ 2
If you want words reversed only you can split the string into a list and operate on each index (or word in this case) and reverse it with the reverse method or [::-1] and then use the join method to put them back together
6th Apr 2020, 3:00 PM
Michael David
Michael David - avatar
+ 2
n = input() print(n[::-1)
7th Apr 2020, 4:50 AM
Akash Agrawal
Akash Agrawal - avatar
+ 1
Try using this reverse slicing. text = "Hello" print (text[::-1]) >>> olleH It will slice the string in reverse order.
5th Apr 2020, 7:55 AM
Abirame Dhevendran
Abirame Dhevendran - avatar
+ 1
This one is very simple. You can do it with List slicing Ex- word=input() print(word[::-1]) It'll do your work Explanation : The third parameter determines the order of string, if you put negative value in it it'll reverse the order of the string. Also, putting negative values in the first two will count from the end of the list.
6th Apr 2020, 8:15 AM
Vishal Sahu
Vishal Sahu - avatar
+ 1
Im still lost. How can P be reversed? wouold you need to determin it via a dictionary?
6th Apr 2020, 9:16 AM
joe oliva
joe oliva - avatar
+ 1
You should read about List slice in detail. You do not dictionary for this. It's a simple procedure
6th Apr 2020, 9:24 AM
Vishal Sahu
Vishal Sahu - avatar
+ 1
U know python or just starting it??
6th Apr 2020, 9:53 AM
Amit Singh Yadav
Amit Singh Yadav - avatar
+ 1
Ramya Thiurmalisamy First try to understand this code: x=[0,1,2,3,4,5] #using ":" will print everything print( x[ : ] ) >>>[0,1,2,3,4,5] #if we want to step 2 numbers we can use third argument as print( x[ 0 : 5 : 2 ] ) >>>[0,2,4] #if we want to start from back we write in the same way but with "-" sign (note: from back the index of 1st digit is -1 not 0 print( x[ -1 : -5 : -2] ) >>>[5,3,1] #now if we want to to print everything without giving indices of 1st two arguments we can use ":" as described earlier(here we used two colons to skip middle argument and include the 3rd argument) print( x[ : : -2] ) >>>[4,2,0] #and if we don't want to skip we can write as print( x[ : : -1] ) >>>[5,4,3,2,1,0] I hope now you have understood the reversing of list.
6th Apr 2020, 6:17 PM
Tricker
+ 1
u_input = input() Print(u_input[0:0:-1])
7th Apr 2020, 1:02 AM
Syed Ahmed Raza Shah
Syed Ahmed Raza Shah - avatar
+ 1
you have to know what a string is
7th Apr 2020, 1:59 AM
Kittylovecode
Kittylovecode - avatar
+ 1
# For mirror output of string Name = input("enter a word") Name.lower() Print(Name(::-1))
7th Apr 2020, 3:48 AM
Mohit Kumar
Mohit Kumar - avatar