Guys, Any idea on how to remove parentheses in my output? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

15th Feb 2018, 2:07 AM
Sai Eshwar
Sai Eshwar - avatar
14 Answers
+ 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
15th Feb 2018, 2:42 AM
jay
jay - avatar
+ 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.
15th Feb 2018, 2:43 AM
Chris
Chris - avatar
+ 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.
15th Feb 2018, 2:47 AM
jay
jay - avatar
+ 5
try it! ( you maybe missing a comma, but if that is what you want it should be fine )
15th Feb 2018, 2:58 AM
jay
jay - avatar
+ 4
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2456/?ref=app re: Best answer, unfortunately, no. Only one maybe selected
15th Feb 2018, 2:55 AM
jay
jay - avatar
+ 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 ;)
15th Feb 2018, 2:08 PM
visph
visph - avatar
+ 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/
15th Feb 2018, 3:31 AM
visph
visph - avatar
+ 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 !
15th Feb 2018, 2:44 AM
Sai Eshwar
Sai Eshwar - avatar
+ 1
@jay, Where can I learn this conversion method ? I mean is it mentioned here in Solo Learn - Python's course ?
15th Feb 2018, 2:53 AM
Sai Eshwar
Sai Eshwar - avatar
+ 1
Btw guys , Can't I select multiple answers under the Best answer ?
15th Feb 2018, 2:54 AM
Sai Eshwar
Sai Eshwar - avatar
+ 1
@ Jay what about this ? print (*a[e:f])
15th Feb 2018, 2:56 AM
Sai Eshwar
Sai Eshwar - avatar
+ 1
Thanks for answering everytime I asked a doubt ! I have my doubts clarified ! Have a Good day buddy ! :) !
15th Feb 2018, 3:00 AM
Sai Eshwar
Sai Eshwar - avatar
+ 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 !
15th Feb 2018, 1:45 PM
Sai Eshwar
Sai Eshwar - avatar
0
Oh,I got it ! Thanks for the explanation !
15th Feb 2018, 3:02 PM
Sai Eshwar
Sai Eshwar - avatar