Re: [Tutor] Splitting lists with strings and integers

2013-11-27 Thread Mark Lawrence
On 27/11/2013 01:18, Dominik George wrote: for x in xrange(len(animal)): if animal[x].isdigit(): animal[x] = int(animal[x]) Before posting anything else would you please do a tutorial yourself. The above for loop is appalling newbie code, I'll leave you to post the Pyth

Re: [Tutor] Splitting lists with strings and integers

2013-11-27 Thread Dominik George
Mark Lawrence schrieb: >Dominik, > >I'm very sorry about the above, I really should know better than to >post >at stupid o'clock in the morning when I'm already exhausted. Thanks, Mark :)! -nik ___ Tutor maillist - Tutor@python.org To unsubscribe or

Re: [Tutor] Splitting lists with strings and integers

2013-11-27 Thread spir
On 11/27/2013 02:18 AM, Dominik George wrote: >Before posting anything else would you please do a tutorial >yourself. The above for loop is appalling newbie code, I'll leave >you to post the Pythonic format. Can I trust my ears? Did you just make a move to expell me from posting newbie-readable

Re: [Tutor] Splitting lists with strings and integers

2013-11-27 Thread spir
On 11/26/2013 08:00 PM, Sam Lalonde wrote: Hi, I am very new to python. I have a list with mixed strings/integers. I want to convert this to a list of lists, and I want the numbers to get stored as integers. list1 = ['dog 1 2', 'cat 3 4', 'mouse 5 6'] There is a little interpretation error

Re: [Tutor] Splitting lists with strings and integers

2013-11-26 Thread Dominik George
> >for x in xrange(len(animal)): > >if animal[x].isdigit(): > >animal[x] = int(animal[x]) > > > > Before posting anything else would you please do a tutorial > yourself. The above for loop is appalling newbie code, I'll leave > you to post the Pythonic format. Can I trust

Re: [Tutor] Splitting lists with strings and integers

2013-11-26 Thread Mark Lawrence
On 27/11/2013 00:57, Dominik George wrote: Hi, I have a list with mixed strings/integers. I want to convert this to a list of lists, and I want the numbers to get stored as integers. First, let's do it with a list comprehension. You should really learn those if you do serious Python program

Re: [Tutor] Splitting lists with strings and integers

2013-11-26 Thread Alan Gauld
On 26/11/13 19:00, Sam Lalonde wrote: >>> list1 = ['dog 1 2', 'cat 3 4', 'mouse 5 6'] >>> list2 = [] >>> for animal in list1: ... animal = animal.split() ... list2.append(animal) ... This could be a list comprehension: list2 = [animal.split() for animal in list1] >>> print list

Re: [Tutor] Splitting lists with strings and integers

2013-11-26 Thread Amit Saha
On Wed, Nov 27, 2013 at 5:00 AM, Sam Lalonde wrote: > Hi, I am very new to python. > > I have a list with mixed strings/integers. I want to convert this to a list > of lists, and I want the numbers to get stored as integers. > list1 = ['dog 1 2', 'cat 3 4', 'mouse 5 6'] list2 = []

Re: [Tutor] Splitting lists with strings and integers

2013-11-26 Thread Dominik George
Hi, > I have a list with mixed strings/integers. I want to convert this to a > list of lists, and I want the numbers to get stored as integers. First, let's do it with a list comprehension. You should really learn those if you do serious Python programming ;)! list2 = [[int(z) if z.isdigit(

[Tutor] Splitting lists with strings and integers

2013-11-26 Thread Sam Lalonde
Hi, I am very new to python. I have a list with mixed strings/integers. I want to convert this to a list of lists, and I want the numbers to get stored as integers. >>> list1 = ['dog 1 2', 'cat 3 4', 'mouse 5 6'] >>> list2 = [] >>> for animal in list1: ... animal = animal.split() ... lis