+ 2
Guys, Any idea on how to remove parentheses in my output?
Here is my Python code, In the output, I am getting Parentheses, and I know why ! But all I want to know is, Is there any possibility of removing it and printing the remaining ? If yes, Please do comment ! Thanking you, Sai Eshwar ! Have a Great day ! https://code.sololearn.com/ccf9N2M34fcJ/?ref=app
14 Respostas
+ 9
replace: print(a[e:f])
with:
temp = [str(arr) for arr in a[e:f]]
print(", " . join(temp))
from: https://stackoverflow.com/questions/11178061/print-list-without-brackets-in-a-single-row
+ 7
Replace this line:
print(a[e:f])
Printing a list will always print parentheses. Instead, go through the list with a for-loop and print the single elements and after another.
+ 7
Like Chris has said, printing a list will always print parentheses.
The answer I provided, first converts the arrays contents into a string array and then joins each element with a comma in-between.
+ 5
try it! ( you maybe missing a comma, but if that is what you want it should be fine )
+ 4
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2456/?ref=app
re: Best answer, unfortunately, no. Only one maybe selected
+ 4
No, simple '*' is for list only, double '**' is for dict only...
Think that unpacking list would produce only one value by item, while unpacking dict would produce a key and a value ;)
+ 3
@Sai Eshwar wrote: << @ Jay what about this ? print (*a[e:f]) >>
Square brackets notation is calling "list slicing", and I guess you already know that, as you seems to use it in your code before @Jay advice ( https://www.pythoncentral.io/how-to-slice-listsarrays-and-tuples-in-JUMP_LINK__&&__python__&&__JUMP_LINK/ ), and '*' in front of a list is called "unpacking operator", which exist also as '**' for "unpacking" dicts: https://codeyarns.com/2012/04/26/unpack-operator-in-python/
+ 1
Thanks for the answers ! but,can anyone tell me,Why your answer works ? I mean, I want to know why it works, and how it works !
+ 1
@jay, Where can I learn this conversion method ? I mean is it mentioned here in Solo Learn - Python's course ?
+ 1
Btw guys , Can't I select multiple answers under the Best answer ?
+ 1
@ Jay what about this ? print (*a[e:f])
+ 1
Thanks for answering everytime I asked a doubt ! I have my doubts clarified ! Have a Good day buddy ! :) !
+ 1
@visph, Just a doubt, So as you told we should use '**' for unpacking dicts, can we use '*' for dicts and '**' for lists as well? Btw Thanks for the great reply !
0
Oh,I got it ! Thanks for the explanation !