454,519 Members | 1,831 Online
Need help? Post your question and get tips & solutions from a community of 454,519 IT Pros & Developers. It's quick & easy.

# break up a value in a list to a list of individual items

 P: n/a Hi, sorry to post this, but I've had a really hard time finding how to do it. Q. How can I break up a value in a list to a list of individual items (preferably without importing any modules)? Like... ['12345'] (string) to [1, 2, 3, 4, 5] [numbers] Thanks. Nov 9 '08 #1
5 Replies

 P: n/a [int(i) for i in ['12345'][0]] Nov 9 '08 #2

 P: n/a On Sun, Nov 9, 2008 at 2:38 AM, r3bol Thanks. -- http://mail.python.org/mailman/listinfo/python-list Nov 9 '08 #3

 P: n/a r3bol >map(int, '12345') [1, 2, 3, 4, 5] HTH -- Arnaud Nov 9 '08 #4

 P: n/a thanks :) and so many different ways! Nov 9 '08 #5

 P: n/a r3bol wrote: Hi, sorry to post this, but I've had a really hard time finding how to do it. Q. How can I break up a value in a list to a list of individual items (preferably without importing any modules)? Like... ['12345'] (string) to [1, 2, 3, 4, 5] [numbers] You did not specify what you want to happen if the original list has more than one item. If you want to keep the other items.... >>lst = [1, '234', 5]lst[1:2] = [int(i) for i in lst[1]] # insert slicelst [1, 2, 3, 4, 5] >>lst = [1, '234', 5]lst[1] = [int(i) for i in lst[1]] # insert itemlst [1, [2, 3, 4], 5] Nov 9 '08 #6

### This discussion thread is closed

Replies have been disabled for this discussion.