I have multiple 1-element lists that I wish to convert into 1 single list:  Current lists:  ['orange'] ['apple'] ['grape'] ['banana'] ['mango']   Wish to have an output like this:  ['orannge', 'apple', 'grape', 'banana', 'mango']   My purpose is to write those array with 1x3 into a csv file  Here is Code:  import csv #import numpy as np  f1 = open('out.csv') data = csv.reader(f1, delimiter=':') print (data) for row in data:     #print(row)     modules = print(row[2:])     #for row in module:      result = [[0,0]]  # iterate through rows for i in modules:     # iterate through columns     for j in modules[0]:         result[j][i] = X[i][j]  for r in result:     print(r)    #Try with zip/map #print(map(data,zip(*module)) #with open('test.csv', 'wb') as f:     #writer = csv.writer(f)     #for row in module:     #writer.writerow(module) f1.close()
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]
I can't seem to edit and save config files in the root system (eg: /etc/dhcp/dhcpd.config); it just says "permission denied" or the save option is blocked in the text editor.  I'm pretty sure I'm a root user, but how do I make sure? If I am a root user, how do I fix this? How to roll the viewport? How do I rotate the viewport around the local (to the view port) - Z axis?  Basically what you would  get if you were to hit R with the camera selected in camera view. Find where java class is loaded from Obviously, most beers are carbonated with carbon dioxide, while some stouts/porters are "carbonated" with nitrogen.  I was curious if there has been any notable experimentation with other gasses to "carbonate" beer. If nitrogen can introduce a "creamy" texture to a beer, I would think that other gasses would also be able to introduce their own characteristics on beer. If any of these experiments have done, what characteristics do these other gases impart?  I'm sure cost would be an issue for certain gasses that would prohibit its use in beer, but for purposes of this question, cost is irrelevant.  As an aside, what is the correct term to use, as opposed to "carbonate", for a question of this nature? Is there a way to view a comment's source? Why does Venus spin in the opposite direction? Given: Law of Conservation of Angular Momentum.   Reverse spinning with dense atmosphere (92 times > Earth &amp; CO2 dominant sulphur based). Surface same degree of aging all over. Hypothetical large impact is not a sufficient answer.   Assuming any object large enough to alter a planets rotation or even orbit would likely destroy most of its shape, yet Venus has retained a spherical property with a seemingly flat, even terrain indicating no volcanoes,and few if any visible meteor impacts. It would be fragmented and dispersed for billions of years.  Even the question of what meteor, comet, asteroid composition could survive traveling that close to the sun's temperature, radiation, electromagnetic energy, solar flares, or gravity to equal a mass reactionary change as to alter it's spin. I've noticed something while trying to prove the properties of parallel lines, and the properties that a triangle has 180 degrees. To prove the properties of parallel lines, such as alternate angles, you need to use the property that a triangle has 180 degrees. To prove a triangle has 180 degrees however, you need to use the properties of parallel lines. This really bothers me because of how circular it is. They are both reliant on each other to be true, and do not logically show, without being reliant on each other, why triangles have 180 degrees, and why parallel line properties are true.   So what I hoping for here is a way to prove parallel line properties without using the fact that a triangle has 180 degrees, or a way to prove triangles have 180 degrees without using parallel line properties. This way, things will be logical to me, and make sense.   Thanks in advance. Is the Ubuntu Phone available anywhere yet? I want start developing apps.  I am very impatient to start to develop on real ubuntu phone. Dynamic loading of python modules Reading the Result of Traceroute When you use tracert www.example.com in the command prompt, what exactly does the returned information tell you, and how does it go about getting that information. Up until now I have only used traceroute to get the I.P. address of a website without really thinking about the bigger purpose of traceroute. I need to use binary variables (values 0 &amp; 1) in k-means. But k-means only works with continuous variables. I know some people still use these binary variables in k-means ignoring the fact that k-means is only designed for continuous variables. This is unacceptable to me.  Questions:     So what is the statistically / mathematically correct way of using binary variables in k-means / hierarchical clustering? How to implement the solution in SAS / R? How can I find the method that called the current method? When logging in C#, how can I learn the name of the method that called the current method? I know all about System.Reflection.MethodBase.GetCurrentMethod(), but I want to go one step beneath this in the stack trace. I've considered parsing the stack trace, but I am hoping to find a cleaner more explicit way, something like Assembly.GetCallingAssembly() but for methods. Automatic image format detection in PHP I am looking for a way to take a user uploaded image that is currently put in a temporary location ex: /tmp/jkhjkh78 and create a php image from it, autodetecting the format.  Is there a more clever way to do this than a bunch of try/catching with imagefromjpeg, imagefrompng, etc? How to get apache to send a 404 based on no matching VirtualHost section (based on ServerName) being found? I am rebuilding an old server.  Only one of the five old sites need to go live and all five of the old sites point to the same IP address.  Unfortunately any time a request is made for one of the old sites via their own unique domain names they are passed the pages from the one site that I'm trying to make live.  I would just like the old sites to display a 404 instead of the one site that I'm actually trying to make live.  As an example:   Site 1 (192.168.0.1) [www.first.com] Site 2 (192.168.0.1) [www.second.com] Site 3 (192.168.0.1) [www.third.com]   I want to move site 1 live again.  So I turned on apache on the machine with the IP address of 192.168.0.1, with all of site 1's files in the /var/www directory.  When I browse to 192.168.0.1 or www.first.com I correctly see site 1. When I browse to www.second.com and www.third.com I also receive site 1 which is the problem.  Is there a way I can 404 any request which comes in without www.first.com?  Here is my sites-available:  NameVirtualHost *:80  LogFormat "%h %l %u %t \"%r\" %&gt;s %b" common  &lt;Files ~ "^\.ht"&gt;     Order allow,deny     Deny from all     Satisfy All &lt;/Files&gt;  &lt;Directory /&gt;   Order Deny,Allow   Deny from all   Options None   AllowOverride None   Options None &lt;/Directory&gt;  &lt;Directory /var/www&gt;   Order Allow,Deny   Allow from all &lt;/Directory&gt;  &lt;VirtualHost *:80&gt;         ServerName first.com         ServerAlias www.first.com         DocumentRoot /var/www         ErrorLog /var/log/first.com.err         CustomLog /var/log/first.com.log common &lt;/VirtualHost&gt;  &lt;VirtualHost _default_:*&gt;         ServerName unknown         DocumentRoot /var/www_404 &lt;/VirtualHost&gt; What's the easiest way to run GUI apps on Windows Subsystem for Linux as of 2018? Is "each" singular or plural? You goes with are. Does the presence of each change this?  How satisfied are each of you with the time you've spent in your respective  universities. How satisfied is each of you with the time you've spent in your respective  universities How do I switch to first person? I suggest that when a post is migrated from one site to another, that the question vote score get reset to zero (or perhaps only a negative vote score is reset to zero). Often people will downvote a question when the only thing that's "wrong" with it is that it's posted on the incorrect site. After migration, those downvotes hang around as a negative score and may unfairly bias the treatment of the question. Prove: If $A$ is a finite set and $B$ is an infinite set, then $B \setminus A$ is an infinite set.   I've tried proving the contrapositive, that if $B \setminus A$ is a finite set then $A$ is infinite or $B$ is finite, but I don't think this is the way to go. Are there surface-mount pin header footprints for KiCAD? I'm designing a small module that breaks out a DIP SPI EEPROM to a 2x5 pin header socket(more info here: ). I want to mount the socket on the end of the board, with the pins lying parallel to the board.  I think two 5x1 surface-mount header footprints, on both sides of the board right near the end would do the job. Trouble is, KiCAD doesn't come with such a footprint(if it does, I haven't found it yet). Where might I find one? If one doesn't exist, that's OK; I'll have a shot at making my own.