I'd like to remove the brackets around my querysets using list comprehension.  This is what I have :   foo = [[&lt;queryset: two&gt;], [&lt;queryset: four&gt;], [&lt;queryset: one&gt;]]    And this is what I want :   bar = [&lt;queryset: two&gt;, &lt;queryset: four&gt;, &lt;queryset: one&gt;]    I tried to use list comprehension like so but it didn't change anything :  bar = [x for x in foo]   What am I doing wrong ?
Is there a simple way to flatten a list of iterables with a list comprehension, or failing that, what would you all consider to be the best way to flatten a shallow list like this, balancing performance and readability?  I tried to flatten such a list with a nested list comprehension, like this:  [image for image in menuitem for menuitem in list_of_menuitems]   But I get in trouble of the NameError variety there, because the name 'menuitem' is not defined.  After googling and looking around on Stack Overflow, I got the desired results with a reduce statement:  reduce(list.__add__, map(lambda x: list(x), list_of_menuitems))   But this method is fairly unreadable because I need that list(x) call there because x is a Django QuerySet object.  Conclusion:   Thanks to everyone who contributed to this question.  Here is a summary of what I learned.  I'm also making this a community wiki in case others want to add to or correct these observations.  My original reduce statement is redundant and is better written this way:  &gt;&gt;&gt; reduce(list.__add__, (list(mi) for mi in list_of_menuitems))   This is the correct syntax for a nested list comprehension (Brilliant summary !):  &gt;&gt;&gt; [image for mi in list_of_menuitems for image in mi]   But neither of these methods are as efficient as using itertools.chain:  &gt;&gt;&gt; from itertools import chain &gt;&gt;&gt; list(chain(*list_of_menuitems))   And as @cdleary notes, it's probably better style to avoid * operator magic by using chain.from_iterable like so:  &gt;&gt;&gt; chain = itertools.chain.from_iterable([[1,2],[3],[5,89],[],[6]]) &gt;&gt;&gt; print(list(chain)) &gt;&gt;&gt; [1, 2, 3, 5, 89, 6]
Linux: coloring bash prompt will break carriage return When I try to colorize the bash prompt like this:  export PS1="\e[0;31m[\u@\h \W]\$ \e[m "   it breaks the carriage return (instead of going to a new line when line is full, it starts in the same line and erases the input text).  If I remove the color sequence it works fine. I use Ubuntu 11.10 and terminal (guake has the same bug too). What does this box icon represent? Since I started playing, I have seen this icon in the bottom right of my screen. Clicking it does nothing.  What does this icon represent?  I'll add a PC tag, as I'm playing on PC, and it could be related to that. Let $P,Q$ real $n\times n$ matrices  such that $P^2=P$ , $Q^2=Q$ and $I-P-Q$ is an invertible matrix.  Prove that $P$ and $Q$ have the same rank.  Some help with this please , happy year and thanks. Leftmargin problem at the bibliography I have some trouble with the bibliography alignment. It's similar to , but that solution doesn't work for me.   Here is MWE:  \documentclass{article}  \let\oldthebibliography=\thebibliography \let\endoldthebibliography=\endthebibliography \renewenvironment{thebibliography}[1]{%   \begin{oldthebibliography}{#1}%   \setlength{\parskip}{0ex}%   \setlength{\itemsep}{0ex}%   \setlength{\itemindent}{3ex}   \setlength{\leftmargin}{0pt}% }% { \end{oldthebibliography}% }  \begin{document}  Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text.    Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text.   \begin{thebibliography}{0} \bibitem{1} Baider A. Noncompact Riemannian manifolds with discrete spectra // J.Diff.Geom. -- 1979 -- V. 14 -- p. 41--57. \bibitem{2} Berger M., Gauduchon P., Mazet E. Le spectre d'une vari\'et\'e Rieman\-nienne -- Berlin-New York: Springer-Verlag, 1971. -- 251p. -- (Lecture Notes in Math.; V.~194) \end{thebibliography} \end{document}   So I need the reference labels to be aligned with the parindent, and the rest part of the each bibliography entry should have general text width. I thought it's enough to set \leftmargin=0pt, but it didn't work. I have the following result:   And what is actually more weird - it seems any value of \leftmargin doesn't have any effect to the bibliography display. The solution from the link above works fine if we don't have biblabel, but it's not my case.  Could you help me to move lines with the red marks to the green one? Why is jumping into water from high altitude fatal? If I jump from an airplane straight positioned upright into the ocean, why is it the same as jumping straight on the ground?  Water is a liquid as opposed to the ground, so I would expect that by plunging straight in the water, I would enter it aerodynamically and then be slowed in the water. Mean and variance of Squared Gaussian: $Y=X^2$ where: $X\sim\mathcal{N}(0,\sigma^2)$? What is the mean and variance of Squared Gaussian: $Y=X^2$ where: $X\sim\mathcal{N}(0,\sigma^2)$?  It is interesting to note that Gaussian R.V here is zero-mean and non-central Chi-square Distribution doesn't work.  Thanks. Why is $\mathbb{Z}[\sqrt{-n}], n\ge 3$ not a UFD? Help finding the limit of $\lim_{n \to \infty}\prod_{k=1}^{n}\left(1+\frac{1}{n}f\left(\frac{k}{n}\right)\right)$. I have B1/B2 Visa. Can I travel for Business trip to US with this Visa? I have been given B1/B2 Visa, but first time when I had applied, it  was for vacation &amp; holiday. Now I need to go to US for business meetings. Is this Visa good enough or do I have to apply for a B1 Visa again?  Note: I originally applied for vacation purposes, but in my visa it is stamped "R b1/b2" What are your favorite English language tools? Show that $\frac 1{1+x+y^{-1}}+\frac1{1+y+z^{-1}}+\frac1{1+z+x^{-1}}=1$ if $xyz=1$ Sorting references with special characters alphabetically I have a problem within the reference list. Namely I have some references where the authors first surname letter is Š (\v{S}) and when listing them in the references they appear amid those authors whose surname starts with V instead after those whose surname starts with S and those whose starts with T (it should list R, S, Š, T... and not R, S, T, U, V with Š in between)  Here is my minimal working example:   \documentclass{article}  \usepackage{filecontents}  \begin{filecontents}{AA.bib}  @article{simovic13, Author = {\v{S}imovi\'{c}, H. and Deskar-\v{S}krbi\'{c}, M.}, Journal = {Zbornik radova Ekonomskog fakulteta u Rijeci}, Number = {1}, Pages = {55--78}, Title = {Dynamic effects of fiscal policy and fiscal multipliers in {Croatia}}, Volume = {31}, Year = {2013}}  @misc{tenhofen07, Author = {Tenhofen, J. and Wolff, G. B.}, Note = {Deutsche Bundesbank Discussion Paper Series 1: Economic Studies No. 14. Frankfurt am Main: Deutsche Bundesbank}, Title = {Does anticipation of government spending matter? Evidence from an expectation augmented {VAR}}, Year = {2007}}  @misc{spilimbergo09, Author = {Spilimbergo, A. and Symansky, S. and Schindler, M.}, Note = {IMF Staff Position Note No. 11. Washington: International Monetary Fund}, Title = {Fiscal multipliers}, Year = {2009}}  @misc{ver11, Author = {Verhelst, S.}, Note = {Egmont Paper, No. 47, Brussels: Egmont Institute}, Title = {The Reform of European Economic Governance: Towards a Sustainable Monetary Union?}, Year = {2011}}  @article{vuckovic10, Author = {Vu\v{c}kovi\'{c}, V.}, Journal = {Privredna kretanja i ekonomska politika}, Number = {125}, Pages = {61--88}, Title = {Political Business Cycles: Do They Exist in {Croatia?}}, Volume = {20}, Year = {2010}}  \end{filecontents}   \begin{document} \nocite{*}   \bibliographystyle{plain} % works % \bibliographystyle{alpha} % works ... % \bibliographystyle{apalike} % works \bibliography{AA} \end{document}   I am thankful for any help!!!  Ana Using global variables in a function How can I create or use a global variable in a function?  If I create a global variable in one function, how can I use that global variable in another function? Do I need to store the global variable in a local variable of the function which needs its access? Arbitrary intersection of closed, connected subsets of a compact space connected? Let $(B_i)_{i\in I}$ be an indexed family of closed, connected sets in a compact space X. Suppose $I$ is ordered, sucht that $i &lt; j \implies B_i \supset B_j$.  Is $B = \bigcap_i B_i$ necessarily connected?  I can prove it, if I assume $X$ to be Hausdorff as well: If $B$ is not connected, then there are two disjoint, closed, nonempty sets $C$, $D$ in $B$, such that $C \cup D = B$. Now these sets are also closed in $X$, hence by normality there exist open disjoint neighborhoods $U$, $V$ of $C$ and $D$, respectively.  Then for all $i$: $B_i \cap U^c \cap V^c \ne \emptyset$, since $B$ is contained in $B_i$ and $B_i$ is connected. Thus we must also have  $$ B \cap U^c \cap V^c = \bigcap_i B_i \cap U^c \cap V^c \ne \emptyset $$  by compactness and the fact that the $B_i$ satisfy the finite intersection property. This is a contradiction to the choice of $U$ and $V$.  I can neither see a counterexample for the general case, nor a proof. Any hints would be greatly appreciated!  Thanks,  S. L. HTTP request parameters are not available by request.getAttribute() Auto-incrementing field in feature class using ArcGIS Desktop? So I'm relatively new to ArcGIS and ArcCatalog.  I have created a field name of PROJECTID in a feature class in a Personal Geodatabase.  The data type is TEXT.  This will be a ten digit ID.  The first five characters will be a acronym.  The sixth character will be a digit that represents the type of feature.  It will be a number.  The last four characters will be numbers that should be incremented starting at 0001.    Example:     WATER-1-0001  Screen shot of the field:   So my question is how can I do this in ArcCatalog.  I've seen some Python code that will autoincrement like the following:  rec=[OBJECTID] def autoIncrement(a):   global rec   return "water" + str(a) + "-" +  format(rec, '04d')   Again I'm a newbie when it comes to ArcGIS . Now I am getting an error NameError name 'OBJECTID' is not defined. How should I use a possessive apostrophe when a name is between commas? The continuity of $f(x,y) = \frac {\sin (xy)} {\sqrt {x^2 + y^2}}$ at $(0,0)$ I got a function:       $f(x,y) = \frac {\sin (xy)}  {\sqrt {x^2 + y^2}}$ if $(x,y) \not =  (0,0)$, otherwise $f(x,y) = 0$,   and I should look at its continuity in $(0,0)$   I tried the sandwich theorem but got slightly stuck unfortunately  $ 0 \le \left|\frac {\sin (xy)}  {\sqrt {x^2 + y^2}}\right| \le 1$   I was thinking that $\sin (xy)$ is a restricted function, but not sure what to with $\sqrt {x^2 + y^2}$ if $x,y$ are too small so I think my idea doesn't work. Then it would look like:  $ 0 \le \left| {\sin (xy)} \right| \le \sqrt {x^2 + y^2} = 0$  Any other idea please? Author information column wise I am using authblk package and I want to achieve following output using this package. Is there a function or method to give the last day of a month? For example if the date is 27 feb 2013, the last date should be 28 feb 2013 , it become 29 if its a leap year. if the date was 2 jan then it should return 31 Jan.  If there is no function then any ideas on how we can get this?  Thanks