Re: list iteration if statement

2009-01-02 Thread Steve Holden
alex goretoy wrote: > v should have ['3','4','1'] sorry if I made it confusing. > [...] Aah, I see I was giving you incorrect advice. I now realise that you want to flatten the lists as well. Don't try to do this with a list comprehension. It won't work without creating an unnecessary list of lis

Re: list iteration if statement

2009-01-02 Thread Steve Holden
alex goretoy wrote: > Thank you Steve and MRAB, > > This is what I was looking for: > > [[v.append(j) for j in i if j != 0] for i in self.value] > No, it wasn't. You should *not* be modifying v in the list comprehension! > the value is actually stored as a string so I would need to check if it

Re: list iteration if statement

2009-01-02 Thread Mensanator
On Jan 2, 8:43�pm, "alex goretoy" wrote: > rather, how do I suppress the output of the list with all None in it? > > >>> l=[['3'], ['0', '4'], ['0', '1'], ['0']] > >>> v=[] > >>> [[v.append(j)for j in i if j != "0"] for i in l] > > [[None], [None], [None], []] > > >>> v > ['39', '32', '1'] > Assi

Re: list iteration if statement

2009-01-02 Thread MRAB
alex goretoy wrote: Thank you Steve and MRAB, This is what I was looking for: [[v.append(j) for j in i if j != 0] for i in self.value] the value is actually stored as a string so I would need to check if it is "0". I do have one more question about list comprehension though. After doing thi

Re: list iteration if statement

2009-01-02 Thread alex goretoy
rather, how do I suppress the output of the list with all None in it? >>> l=[['3'], ['0', '4'], ['0', '1'], ['0']] >>> v=[] >>> [[v.append(j)for j in i if j != "0"] for i in l] [[None], [None], [None], []] >>> v ['39', '32', '1'] >>> On Sat, Jan 3, 2009 at 2:38 AM, alex goretoy wrote: > Thank yo

Re: list iteration if statement

2009-01-02 Thread Steven D'Aprano
On Sat, 03 Jan 2009 01:52:04 +, alex goretoy wrote: > Hello All, > > I'm doing this in my code > > [[v.append(j) for j in i] for i in self.value] > > if works and all, Replacing "self.value" with a list of lists of ints: >>> list_of_lists = [[1, 2, 3], [2, 4, 6]] >>> v = [] >>> output = [

Re: list iteration if statement

2009-01-02 Thread alex goretoy
v should have ['3','4','1'] sorry if I made it confusing. On Sat, Jan 3, 2009 at 2:43 AM, alex goretoy wrote: > rather, how do I suppress the output of the list with all None in it? > > >>> l=[['3'], ['0', '4'], ['0', '1'], ['0']] > >>> v=[] > >>> [[v.append(j)for j in i if j != "0"] for i in l]

Re: list iteration if statement

2009-01-02 Thread alex goretoy
Thank you Steve and MRAB, This is what I was looking for: [[v.append(j) for j in i if j != 0] for i in self.value] the value is actually stored as a string so I would need to check if it is "0". I do have one more question about list comprehension though. After doing this I get an unwanted list

Re: list iteration if statement

2009-01-02 Thread Steve Holden
alex goretoy wrote: > Hello All, > > I'm doing this in my code > > [[v.append(j) for j in i] for i in self.value] > > if works and all, but I need to add a if statement in the mix. Can't > seem to remember the syntax to do so and everything I've tried seems to > fail. How do I add a check to see

Re: list iteration if statement

2009-01-02 Thread MRAB
alex goretoy wrote: Hello All, I'm doing this in my code [[v.append(j) for j in i] for i in self.value] if works and all, but I need to add a if statement in the mix. Can't seem to remember the syntax to do so and everything I've tried seems to fail. How do I add a check to see if j is not i

list iteration if statement

2009-01-02 Thread alex goretoy
Hello All, I'm doing this in my code [[v.append(j) for j in i] for i in self.value] if works and all, but I need to add a if statement in the mix. Can't seem to remember the syntax to do so and everything I've tried seems to fail. How do I add a check to see if j is not int("0") then append to v