Re: [Tutor] Creating a list from other lists

2012-10-23 Thread Walter Prins
 It's an HTML post.

 Not according to the version of Thunderbird I am using, which shows it
 as a plain text email.

 I suspect that the HTML attachment may be invalid HTML, understandable
 by Gmail and possibly nothing else. Typical of Google :(

Looking at the email source it clearly shows as being mimetype
multipart with both a plaintext and HTML part.  I don't think you
can much criticise GMail for interpreting and attempting to render an
HTML email as HTML.  The biggest culprit here IMHO was the sending
mail client that generated a broken text mode version of the email's
intended formatting by dropping the indentation (and if the HTML is
broken, generated broken HTML to boot as well.)

Walter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Creating a list from other lists

2012-10-23 Thread Steven D'Aprano

On 23/10/12 19:51, Walter Prins wrote:

It's an HTML post.


Not according to the version of Thunderbird I am using, which shows it
as a plain text email.

I suspect that the HTML attachment may be invalid HTML, understandable
by Gmail and possibly nothing else. Typical of Google :(


Looking at the email source it clearly shows as being mimetype
multipart with both a plaintext and HTML part.  I don't think you
can much criticise GMail for interpreting and attempting to render an
HTML email as HTML.


Perhaps not, but I can criticize Gmail for offering such an anti-feature
in the first place.



The biggest culprit here IMHO was the sending
mail client


That would be Gmail, almost certainly.



that generated a broken text mode version of the email's
intended formatting by dropping the indentation (and if the HTML is
broken, generated broken HTML to boot as well.)


I don't actually know if the HTML part is broken or not. I saved it and
opened it in Firefox, and Firefox rendered it as raw text showing the
tags. Perhaps that just means my test was faulty.

Either way though, I'm sick to the back teeth of Google-related
technologies being user hostile. Whether it is the horror that Google
Groups has become, Google's search engine tracking and bubbling you
when you search, Google illegally installing tracking cookies AND
THEN LYING ABOUT IT to the American FTC, the awfulness of their image
search interface (which just about every search engine now apes), and
their efforts to link everything you do on the Internet to a Google
account which can be matched to your offline identity, I think their
motto is now best described as Do be evil.


--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Creating a list from other lists

2012-10-23 Thread eryksun
On Tue, Oct 23, 2012 at 4:51 AM, Walter Prins wpr...@gmail.com wrote:

 Looking at the email source it clearly shows as being mimetype
 multipart with both a plaintext and HTML part.  I don't think you
 can much criticise GMail for interpreting and attempting to render an
 HTML email as HTML.  The biggest culprit here IMHO was the sending
 mail client that generated a broken text mode version of the email's
 intended formatting by dropping the indentation (and if the HTML is
 broken, generated broken HTML to boot as well.)

The message looks to have been sent with Gmail's webmail client. The
problem I think starts with Webkit. When the user presses tab in a
rich text box, instead of tabbing between fields on the page, it
inserts a span class=Apple-tab-span stylewhite-space:pre
element.

I tested how Gmail handles this by creating a simple HTML file
containing the following:

divfor x, y , z in zip(a, b, c):/divdivspan
class=Apple-tab-span style=white-space:pre /spanL.extend([x, y,
z])/divdivspan class=Apple-tab-span
style=white-space:pre/spanprint L/div

I rendered this in Firefox and copied it into a new rich text email.
Gmail stripped out the tab characters before rendering the plain text
section as follows:

for x, y , z in zip(a, b, c):
L.extend([x, y, z])
print L

They certainly could be smarter when it comes to spans with
whitespace:pre styling, but it's better if users would just think to
use plain text when posting code.

That said, plain text with Gmail has its own pitfalls. To render it
correctly with a monospace font in the web client you need to use
something like Stylish to hack Gmail's CSS. But, more importantly, you
have to be wise to Google's line wrapping at 69 characters (no RFC
requires this). It doesn't give you a live preview. Instead you have
to manually wrap code at 69 columns in an IDE and paste it into the
text box. Otherwise your code will probably get mangled.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Creating a list from other lists

2012-10-22 Thread Walter Prins
Hi Saad,

On 22 October 2012 11:21, Saad Javed sbja...@gmail.com wrote:
 Hi,

 I'm trying to create a list (L) from items of different lists (a, b, c) but
 in a specific order (L = [[a1, b1, c1], [a2, b2, c2]...etc])
 L = []
 a = [1, 2, 3, 4]
 b = ['a', 'b', 'c', 'd']
 c = [2009, 2010, 2011, 2012]

 for x, y , z in zip(a, b, c):
 L.extend([x, y, z])
 print L

 But this outputs:
 [[1, 'a', 2009]]
 [[1, 'a', 2009], [2, 'b', 2010]]
 [[1, 'a', 2009], [2, 'b', 2010], [3, 'c', 2011]]
 [[1, 'a', 2009], [2, 'b', 2010], [3, 'c', 2011], [4, 'd', 2012]]

 I just want L = [[1, 'a', 2009], [2, 'b', 2010], [3, 'c', 2011], [4, 'd',
 2012]]

You've already asked essentially this question on another thread -- in
general please don't start new threads for the same question but
continue the discussion on the original question for the sake of
continuity and avoiding wasting people's time.  (New readers of the
new question may not be aware of the previous discussion, and may
expend time and energy addressing issues which have already been
discussed in the previous question.)

As for your problem: You're printing the list every iteration of the
loop which is why your output looks the way it does.   Instead put
your print statement after the loop and you'll see the list you get
after the loop is in fact what you say you want.

However, that doesn't actually solve your problem, because you're
putting the input data into the lists in sorted order already.  You
should jumble up your input data to ensure you also solve the sorting
aspect of this problem (or use the input data from your original
problem which was jumbled up enough already.)

Hint, to deal with sorting your output list, refer to the list.sort()
method and the key   parameter.  See also the Sorting HowTo on the
PythonInfo wiki by Raymond Hettinger:
http://wiki.python.org/moin/HowTo/Sorting/

Hope is enough to get you going,

Walter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Creating a list from other lists

2012-10-22 Thread Steven D'Aprano

On 22/10/12 21:21, Saad Javed wrote:

Hi,

I'm trying to create a list (L) from items of different lists (a, b, c) but
in a specific order (L = [[a1, b1, c1], [a2, b2, c2]...etc])
L = []
a = [1, 2, 3, 4]
b = ['a', 'b', 'c', 'd']
c = [2009, 2010, 2011, 2012]

for x, y , z in zip(a, b, c):
L.extend([x, y, z])
print L


This is not your code, because that gives a SyntaxError. Where is
the indentation? Indentation is required in Python, if you leave it
out, your code will not work correctly. You should have either:

# Option 1
for x, y , z in zip(a, b, c):
L.extend([x, y, z])
print L


which will extend the list four times, and print the list four times,
once each time through the loop. Or:


# Option 2
for x, y , z in zip(a, b, c):
L.extend([x, y, z])

print L  # this is not indented, so it is outside the loop



Now the list only gets printed once, after the for loop has
completely finished, and you don't see the intermediate results.




But this outputs:
[[1, 'a', 2009]]
[[1, 'a', 2009], [2, 'b', 2010]]
[[1, 'a', 2009], [2, 'b', 2010], [3, 'c', 2011]]
[[1, 'a', 2009], [2, 'b', 2010], [3, 'c', 2011], [4, 'd', 2012]]

I just want L = [[1, 'a', 2009], [2, 'b', 2010], [3, 'c', 2011], [4, 'd',
2012]]


Then don't print the list four times, only print it once.




--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Creating a list from other lists

2012-10-22 Thread eryksun
On Mon, Oct 22, 2012 at 6:37 AM, Steven D'Aprano st...@pearwood.info wrote:
 On 22/10/12 21:21, Saad Javed wrote:

 for x, y , z in zip(a, b, c):
 L.extend([x, y, z])
 print L

 This is not your code, because that gives a SyntaxError. Where is
 the indentation? Indentation is required in Python, if you leave it
 out, your code will not work correctly.

It's an HTML post. Using these styled span tags never translates
well to the text/plain section.

div

for x, y , z in zip(a, b, c):

/div
div
span class=Apple-tab-span style=white-space:pre   /span

L.extend([x, y, z])

/div
div
span class=3DApple-tab-span style=3Dwhite-space:pre   /span

print L

/div
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Creating a list from other lists

2012-10-22 Thread Walter Prins
Hi Saad,

On 22 October 2012 11:37, Steven D'Aprano st...@pearwood.info wrote:
 On 22/10/12 21:21, Saad Javed wrote:
 I'm trying to create a list (L) from items of different lists (a, b, c)
 but
 in a specific order (L = [[a1, b1, c1], [a2, b2, c2]...etc])
 L = []
 a = [1, 2, 3, 4]
 b = ['a', 'b', 'c', 'd']
 c = [2009, 2010, 2011, 2012]

 for x, y , z in zip(a, b, c):
 L.extend([x, y, z])
 print L


 This is not your code, because that gives a SyntaxError. Where is
 the indentation? Indentation is required in Python, if you leave it
 out, your code will not work correctly. You should have either:

Just to note: For me your (Saad's) indentation showed perfectly fine
on GMail.  I'm note sure why Steven didn't see it (I think he reads
only plaintext email), so I'd guess perhaps your email included both
HTML and plain text parts and the plain text part perhaps had the
indentation stripped out and the HTML did not.  Anyway point being,
it's best to post plain text if you're emailing unless you absolutely
must use HTML, certainly this is the best way for this mailing list.

Regards,

Walter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Creating a list from other lists

2012-10-22 Thread Steven D'Aprano

On 22/10/12 21:52, eryksun wrote:

On Mon, Oct 22, 2012 at 6:37 AM, Steven D'Apranost...@pearwood.info  wrote:

On 22/10/12 21:21, Saad Javed wrote:


for x, y , z in zip(a, b, c):
L.extend([x, y, z])
print L


This is not your code, because that gives a SyntaxError. Where is
the indentation? Indentation is required in Python, if you leave it
out, your code will not work correctly.


It's an HTML post.



Not according to the version of Thunderbird I am using, which shows it
as a plain text email.

I suspect that the HTML attachment may be invalid HTML, understandable
by Gmail and possibly nothing else. Typical of Google :(



--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor