+ 1
How to solve that?
At the last part from line 57-60. It showing some different type output where it should shown a reverse text of a tuple. So, I need a solution. The code is⤵️ https://code.sololearn.com/c3cKEgdtazs7/?ref=app
6 Réponses
+ 5
Mustakim Rahman , Ipang ,
converting a string or a reversed string to a tuple has some pitfalls, as you can see in the samples and results. to get an expected result, we have to use a trailing comma.
have look at the samples and results in the attached file:
https://code.sololearn.com/cuIh6U72X2jc/?ref=app
+ 3
Is there a particular purpose of wrapping the string in a `tuple` that you can't simply reverse the string?
t = ( "Pyhon" ) is not a tuple. It's still a string.
t = ( "Python", ) is a tuple
+ 2
but brother adding t=("python") to that code is still showing different types output..!
+ 2
Mustakim Rahman
your code suffers from bad variable naming.
In the top part, you used tuple, str and list as variable names.You should not do this, because they are reserved keywords
That is why you are unable to use them as functions later on, so you get errors.
Rename the variables tuple1, str1, list1, list2.
Sololearn does not have linting helper that warns you of these problems.
+ 1
still not solved yet!
0
# create a `tuple` from string "python"
t = tuple( "python" )
# reversed() returns a `reversed` object
# so we need to convert it back to a `tuple`
y = tuple( reversed( t ) )
# now we have a reversed `tuple`
print( f"{y = }\n<y> is a {type( y )}" )