If I have a list like:  a = ['AB', ['CD', 'DE'], 'FG']   How do I transform it to a 2D list as shown:  [['AB', 'CD', 'FG'], ['AB', 'DE', 'FG']]   Using itertools.product also expands 'AB' to 'A', 'B'.
1477
How can I get the Cartesian product (every possible combination of values) from a group of lists?  Input:   somelists = [    [1, 2, 3],    ['a', 'b'],    [4, 5] ]   Desired output:  [(1, 'a', 4), (1, 'a', 5), (1, 'b', 4), (1, 'b', 5), (2, 'a', 4), (2, 'a', 5) ...]
53456
What is the difference between:  some_list1 = [] some_list1.append("something")   and  some_list2 = [] some_list2 += ["something"]
1888
I want to do something like String.Format("[{0}, {1}, {2}]", 1, 2, 3) which returns:  [1, 2, 3]   How do I do this in Python?
2695
Some of you may recognize this as Project Euler's problem number 11. The one with the grid.  I'm trying to replicate the grid in a large multidimensional array, But it's giving me a syntax error and i'm not sure why  grid = [  [ 08, 02, 22, 97, 38, 15, 00, 40, 00, 75, 04, 05, 07, 78, 52, 12, 50, 77, 91, 08 ], [ 49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 04, 56, 62, 00 ], [ 81, 49, 31, 73, 55, 79, 14, 29, 93, 71, 40, 67, 53, 88, 30, 03, 49, 13, 36, 65 ], ...   And I get this error:     File "D:\development\Python\ProjectEuler\p11.py", line 3     [ 08, 02, 22, 97, 38, 15, 00, 40, 00, 75, 04, 05, 07, 78, 52, 12, 50, 77, 91 , 08 ],        ^ SyntaxError: invalid token   Why is it throwing an error before the comma?
753
Sometimes, I'm getting as an input tab separated list, which is not quite aligned, for instance  var1  var2  var3 var_with_long_name_which_ruins_alignment  var2 var3   Is there an easy way to render them aligned?  var1                                      var2  var3 var_with_long_name_which_ruins_alignment  var2  var3
84084
I'm trying to get a list of custom labels. Here is what I've tried:  \begin{enumerate}[Exercise (1)]  \item first  \item second  \end{enumerate}   This results in each item being labeled as: Exerc#se (#)  Where # is the number of the item in the list. How can I make the "i" in exercise not be pattern matched?   Using a \ doesn't work, it causes syntax error.
15132
I'm looking to replace list comprehensions like the following with something more efficient and I was wondering if numpy can be used.  [obj.matrix_world @ v.co for v in obj.data.vertices]   I can do this, which is significantly faster, but still lacks the matrix multiplication, that needs to happen for each coordinate.  coords = np.empty((len(obj.data.vertices), 3), 'f') obj.data.vertices.foreach_get('co', np.reshape(coords, len(obj.data.vertices) * 3))   I was hoping it would just be  np.matrix(obj.matrix_world) @ coords   But that fails with (FWIW, It's just a cube, hence (8, 3))  ValueError: shapes (4,4) and (8,3) not aligned: 4 (dim 1) != 8 (dim 0)   Similarly, doing   for co in coords:     np.matrix(obj.matrix_world) @ co   fails with  ValueError: shapes (4,4) and (3,) not aligned: 4 (dim 1) != 3 (dim 0)   So I've hit a wall now. Numpy can't multiply a 4x4 matrix with a 3d vector, but Blender can. How do I solve this in a numpy way?    edit:  Based on @JoseConseco's excellent reply below, this is what I'm doing now  mx = active.matrix_world verts = active.data.vertices vert_count = len(verts)  coords = np.empty((vert_count, 3), 'f') verts.foreach_get('co', np.reshape(coords, vert_count * 3))  coords_4d = np.ones((vert_count, 4), 'f') coords_4d[:, :-1] = coords  coords = np.einsum('ij,aj-&gt;ai', mx, coords_4d)[:, :-1]   Note, that there's no need to convert the (mathutils) Matrix into an np array. It works fine just like that.  Based on my tests, doing this via numpy is ~3 times faster than the list comprehension.
90301
Formatting breaks if code follows a list:   List item List item  This is in a code block  This does not work as expected   However, it works if between the list and the code   List item List item   There is a line of normal text.  This is in a code block # This does work as expected   Edit  To make this clear: This is not about nesting code in a list but about code following a (finished) list not working as expected (by me). To put it differently: Why is a list not considered finished despite of following empty lines? What do I have to do?
36961
I would like to create something like a=array[1,2,15,6,18] and then a[0]=1, a[1]=2. Is it possible to create an array in LaTeX (with pgf or another package)?
38558
I have a file with the lines like below.  title1:A1 title2:A2 title3:A3 title4:A4 title5:A5  title1:B1 title2:B2 title3:B3 title4:B4 title5:B5  title1:C1 title2:C2 title3:C3 title4:C4 title5:C5  title1:D1 title2:D2 title3:D3 title4:D4 title5:D5  How can I achieve this?   title1    title2     title3    title4 A1         A2         A3         A4 B1         B2         B3         B4 C1         C2         C3         C4 D1         D2         D3         D4
8318
I have a list like so.  blue-image1.jpg, blue-image2.jpg, blue-image3.jpg red-image1.jpg, red-image2.jpg, red-image3.jpg   It's was originally a csv format but I added newlines because they needed a prefix at first. Now I need to put them together again so it becomes like this.  blue-image1.jpg,blue-image2.jpg,blue-image3.jpg red-image1.jpg,red-image2.jpg,red-image3.jpg   I tried cat list.txt | tr ',\n' ',' and cat list.txt | sed 's/,\n/,/g'  but neither seem to work properly.
44787
If you are creating a 1d array, you can implement it as a List, or else use the 'array' module in the standard library.  I have always used Lists for 1d arrays.  What is the reason or circumstance where I would want to use the array module instead?  Is it for performance and memory optimization, or am I missing something obvious?
4474
Assume I have the following list:  foo = ['a', 'b', 'c', 'd', 'e']   What is the simplest way to retrieve an item at random from this list?
9898
Code like this often happens: l = [] while foo:     # baz     l.append(bar)     # qux  This is really slow if you're about to append thousands of elements to your list, as the list will have to be constantly resized to fit the new elements. In Java, you can create an ArrayList with an initial capacity. If you have some idea how big your list will be, this will be a lot more efficient. I understand that code like this can often be refactored into a list comprehension. If the for/while loop is very complicated, though, this is unfeasible. Is there an equivalent for us Python programmers?
50950
Is there a way to convert a List(of Object) to a List(of String) in c# or vb.net without iterating through all the items? (Behind the scenes iteration is fine – I just want concise code)  Update: The best way is probably just to do a new select  myList.Select(function(i) i.ToString()).ToList();   or  myList.Select(i =&gt; i.ToString()).ToList();
3482
This might seem like a very simple question, but what is the easiest way to turn a normal vertical list into a horizontal one?
5259
Is there a guide out there on how to customize the enumerate and itemize instances in my code?  (I'm using the Memoir class in LaTeX for Windows, and I have the enumitem package included.)  I want to mess with the margins and spacings to make my lists look a little less "LaTeX-default"...