Re: list() strange behaviour

2021-01-24 Thread jak

Il 20/12/2020 21:00, danilob ha scritto:

Hi,
I'm an absolute beginner in Python (and in English too ;-)
Running this code:


--
# Python 3.9.0

a = [[1, 2, 0, 3, 0],
  [0, 4, 5, 0, 6],
  [7, 0, 8, 0, 9],
  [2, 3, 0, 0, 1],
  [0, 0, 1, 8, 0]]


b = ((x[0] for x in a))

print(list(b))
print(list(b))
---


I get this output:

[1, 0, 7, 2, 0]
[]


I don't know why the second print() output shows an empty list.
Is it possible that the first print() call might have changed the value 
of "b"?


Thank you in advance.


You should see a generator as a container emptying while you are reading 
it, so you should recreate it every time:



# Python 3.9.0

a = [[1, 2, 0, 3, 0],
 [0, 4, 5, 0, 6],
 [7, 0, 8, 0, 9],
 [2, 3, 0, 0, 1],
 [0, 0, 1, 8, 0]]


b = lambda : (x[0] for x in a)

print(list(b()))
print(list(b()))

output:
[1, 0, 7, 2, 0]
[1, 0, 7, 2, 0]

--
https://mail.python.org/mailman/listinfo/python-list


Jupyter notebooks to A4 (again)

2021-01-24 Thread Martin Schöön
Hello all,

Some years ago I asked about exporting notebooks to pdf in
A4 rather than US Letter. I got help, rather detailed
instructions from you in general and Piet von Oostrum in
particular. Following the advice helped and I was happy.

Now it does not work any longer:

 nbconvert failed: A4article

I am stumped. I have not changed anything and all
looks OK.

Today I tried up-dating all things Python and Jupyter
but that did not help.

I have also tried removing the A4 stuff and after 
restarting Jupyter I can export to PDF and get US Letter
paper format.

A quick and (obviously) not very clever internet search
yielded nothing helpful.

Any ideas?

/Martin
-- 
https://mail.python.org/mailman/listinfo/python-list