How to turn a list of int's to a string with a ',' seperator

This is the place for queries that don't fit in any of the other categories.

How to turn a list of int's to a string with a ',' seperator

Postby Pharo17 » Thu May 22, 2014 11:46 am

I am a newbe at python programming, programming in general.

I have a function with a list:
Code: Select all

I wan't it to print out like this:
Code: Select all

my code
Code: Select all
 def myString(alist):
for i in range(len(alist)):
return s

I can get it the function print the list with the comma on the end, but i do not wan't the last comma to print
How can i achieve this.
Thank you
Last edited by Yoriz on Thu May 22, 2014 12:06 pm, edited 1 time in total.
Reason: Changed title.
Posts: 3
Joined: Wed Apr 09, 2014 3:49 am

Re: lists

Postby Yoriz » Thu May 22, 2014 12:01 pm

Code: Select all

Your list has no value between 4 and 7 and would produce a syntax error.

Code: Select all
alist = [2, 4, 5, 7, 8, 2, 1, 4, 0, 7, 8, 1]

print ','.join(map(str, alist))

Code: Select all
Due to the reasons discussed here we will be moving to on October 1 2016
This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
Posts: 1671
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 4 guests