|
Original question: Can someone tell me how to use "slice lists" and the "ellipsis"? When are they useful? Thanks.
Here's what the language definition says about "slice_list" and "ellipsis"; Alex Martelli's answer points out their origin, which is not ...
Started by behindthefall on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Here goes list slicing:
I hope you know that list....
Slice lists and ellipsis were originally introduced not too sure about ellipsis, so I will not address that, lest I give you a bad answer.
Numpy uses them to implement array slicing.
|
|
I'm trying to find a neat way of summing a list and a list of lists in the same function, so far I've got:
import operator """ Fails late for item = ['a', 'b'] """ def validate(item): try: return sum(item) == sum(range(1, 10)) except TypeError: return...
Started by MattyW on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Perhaps you'd find it easier to flatten the list first?
def flatten(xs): for x in xs: try: sub this:
In [4]: fs = flatten([1,2,[3,4,[5,6],7],8,[9,10]]) In [5]: list(fs) Out[5]: [1, 2, 3, 4, 5, 6, 7 that it doesn't work on mixed lists....
|
|
This is a great primer but doesn't answer what I need: http://stackoverflow.com/questions/464342/combining-two-sorted-lists-in-python
I have two Python lists, each is a list of datetime,value pairs:
list_a = [['1241000884000', 3], ['1241004212000', 4]...
Started by Adam Nelson on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
Merged= list( merge_lists( someDict['object_a'], someDict['object_b'] )
This may be slightlyHere's some code....
Has each datetime from list_x and value_a/value_x."
def merge_lists( list_a, list_x ): dict_x= dict.
|
Ask your Facebook Friends
|
I have 2 lists of elements '(a b c) '(d b f) and want to find differences, union, and intersection in one result. Is that possible? How?
I wrote a member function that checks if there is a car of the first list in the second list, but I can't throw a ...
Started by merci on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Assuming list2) (list (difference lis1 lis2) ....
Sure it is possible.
Take a piece at a time.
Here are a couple hints:
what's the result of combining a list and an empty list? You don't have to do it all at once.
Sure it's possible.
|
|
I'm trying to show someone a use for interfaces in a crazy situation they've created. They have several unrelated objects in lists, and need to perform an operation on two string properties in each object. I'm pointing out that if they define the properties...
Started by OwenP on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
So if you take the loop.
The foreach does a built in cast.
IEnumerable<SP> list) where SP: ISpecialProperties { foreach (var item in list) { Console.WriteLine("{0 just use a foreach on the lists you have.
|
|
Single and multiple lists
Consider the following lists:
List<Int32> appleIdentities = new List<int>(new[] { 1, 2, 3 }); List<Int32> chocolateIdentities = new List<int>(new[] { 2, 3, 4 }); List<Int32> icecreamIdentities = ...
Started by roosteronacid on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
I'm not sure about your third query though - I think you'd need a list for each of the separate Contains the appleIdentities list....
That should be okay for lists and arrays.
Although it'll fail when the lists get big enough IIRC.
|
|
I'm using a list of lists to store a matrix in python. I tried to initialise a 2x3 Zero matrix as follows.
mat=[[0]*2]*3
However, when I change the value of one of the items in the matrix, it changes the value of that entry in every row, since the id ...
Started by Alasdair on
, 9 posts
by 8 people.
Answer Snippets (Read the full thread at stackoverflow):
Use a list][0] = 1 [[1, 0], [0, 0], [0, 0]]
Aka List comprehension; from the docs :
List comprehensions provide a concise....
The resulting list definition tends often to be clearer than lists built using those constructs.
|
|
I have to implement an algorithm to decompose 3D volumes in voxels. The algorithm starts by identifying which vertexes is on each side of the cut plan and in a second step which edge traverse the cutting plan.
This process could be optimized by using ...
Started by chmike on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Most applications spending most overhead in creating a sorted list....
If you have a sorted list, adding to it takes more time, but accessing it is quicker.
list, adding to it takes no time, and accessing particular items takes extra time.
|
|
Hello there - i'm trying to have 3 levels of lists all of which are sortable & draggable into each other. Basically trying to set up an easy way to manage navigation menus with multiple levels.
Its 90% there but for some reason it wont save an item into...
Started by daniel Crabbe on
, 4 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Edit: I used source code: 10px;} </style> </head> <body....
Or parent or what, it only sees if you drag a level 3 item to a level 1 list that the classes are the same and that it should be able to drag that item into that list.
|
|
Below is some linqpad test code. When this runs it errors because the second instance of "item" has a null list of subitems as opposed to an empty list.
I want to treat both situations (null or empty list) in exactly the same way but I wondered if there...
Started by Chris Simpson on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
You could make the item constructor so that it defaults subitem to an empty list.
Subitems to be null.
|