0
Let's say I have this list a= [1 2 3 4] is it possible to convert it to a normal comma separated list like this a = [1, 2, 3, 4]
I have been searching for a long time and I can't seem to find an answer thanks to anybody who answers this!!!!!! :)
4 ответов
+ 3
Well, I'm not sure that a = [1 2 3 4] is even a valid list to begin with. If you're adding elements to a list, then I'd use a loop to add them instead of typing out 1 - 100, commas or not. If you're manually typing out 1-100, then it won't hurt you to add the commas while you're doing that, but again, that's a horrible way to create a list/array in any language.
So to answer you, I'd use a loop to create your list and utilize the list methods to do so properly.
https://docs.python.org/3/tutorial/datastructures.html
^Read through this and learn more on how it all works.
Also, if you find yourself in a situation where you're dealing with a string, you can add commas using the split method. That's worth reading up on as well.
Hopefully that helps you out some. Python is my least fav language, and I'm far from being an expert in it, so I recommend that you do some research/reading on it as well. Best of luck.
+ 2
Maybe I misunderstand what you're asking. Just click the left mouse button after each number and hit the comma key. :D
a = [1, 2, 3, 4]
+ 1
Does this have to be in python or other languages are OK too?
0
haha yes you can always do that but what if your list is huge like from 1 to 100 and you want to add the commas automatically with code?