How would you describe the running time of this sort, given a function sorted which returns True if the list is sorted that runs in O(n):
def sort(l):
while not sorted(l): random.shuffle(l)
Assume shuffling is perfectly random.
Would this be written in big-O notation? Or is there some other way of categorizing algorithms with ra...
How do I select the unique elements from the list {0, 1, 2, 2, 2, 3, 4, 4, 5} so that I get {0, 1, 3, 5}, effectively removing the repeated elements {2, 4}?
...
I have a few model classes with basic one-to-many relationships. For example, a book has many recipes, and each recipe has many ingredients:
class Book(models.Model):
name = models.CharField(max_length=64)
class Recipe(models.Model):
book = models.ForeignKey(Book)
name = models.CharField(max_length=64)
class Ingredient(mo...
Hello! I'm currently working on a very short project on Prolog, and just got stuck trying to apply a "filter" I have created to a list. I have what you could call the filter ready, but I can't apply it. It'd be better if I illustrate:
filter(A, B)
...outputs 'true' if certain conditions are met.
filterList(A, [X, Y, Z])
...outputs ...
Is it possible to create a list that can be access by either an index or a key?
I am looking for a Collection type that already exists but has this facility, I want to avoid redefining the indexers
...
I am trying to use a Generic Linked List to hold some WorkFlow steps in my application. Here is how I'm persisting it to my database.
OrderID WorkFlowStepID ParentWorkFlowStepID
178373 1 NULL
178373 2 1
178373 3 2
I get this dataset back in a datareader...
Let's say, as an example, I have the following list:
foo = ['a', 'b', 'c', 'd', 'e']
What is the best way to retrieve an item at random from this list?
...
I need to create some functionality in our SharePoint app that populates a list or lists with some simple hierarchical data. Each parent record will represent a "submission" and each child record will be a "submission item." There's a 1-to-n relationship between submissions and submission items. Is this practical to do in SharePoint? ...
Everyone is familiar with this functionality. If you open up the the outlook address book and start typing a name, the list below the searchbox instantly filters to only contain items that match your query. .NET Reflector has a similar feature when you're browsing types ... you start typing, and regardless of how large the underlying a...
How to list the contents of a zipped folder in C#? For example how to know how many items are contained within a zipped folder, and what is their name?
...
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 constantly be re-initialized to grow. (I understand that lists aren't just wrappers around some array-type-thing, but something more complicated....
I have a list of arbitrary length, and I need to split it up into equal size chunks and operate on it. There are some obvious ways to do this, like keeping a counter and two lists, and when the second list fills up, add it to the first list and empty the second list for the next round of data, but this is potentially extremely expensive....
We have created a new List View Style that shows thumbnails from a picture library, we have added a HyperLink Column and made the View style map the HyperLink url to an anchor tag.
The intention is that when the Content Managers want to create a image based list of hyper links they just have to create a Picture Library, and then add a w...
Does anyone know if there's a way to automatically expand a list in Python, separated by commas? I'm writing some Python code that uses the MySQLdb library, and I'm trying to dynamically update a list of rows in a MySQL database with certain key values.
For instance, in the code below, I'd like to have the numeric values in the record_...
I'm needing to make this layout editor that uses a good bit of jQuery for letting one resort the items on their resume. I envisioned showing a dialog with a graphical representation of the sections, sort of like:
[Details - locked -- immovable]
[Overview -- immovable, but can be hidden or shown again]
----imaginary line where things can...
Hi, I'm currently having a problem with a ShoppingCart for my customer.
He wants to be able to add Text between the CartItems so I was wondering if there is some way to still only have one List.
My solution would be to have two lists, one of type IList that gets iterated over when calculating Weight and overall Price of the Cart while ...
I am printing out a list of college majors we offer, then within each major, we have concentrations for each major.
Our Science Major has the following concentrations: Environmental Science & Forestry, Chiropractic, Chemistry, Biology
Here is a screen shot of what it is doing:
I do not want the spacing it displays (I do not want the ...
I want to generate a list in C#. I am missing python's list comprehensions. Is there a c# way to create collections on the fly like list comprehensions or generator statements do in python?
...
I occasionally see the list slice syntax used in Python code like this:
newList = oldList[:]
Surely this is just the same as:
newList = oldList
Or am I missing something?
...
A friend of mine is studying Engineering in college. I've never studied / used C++ as I've always stuck to .NET and web based programming. When I heard her Intro. to Programming course was going to teach them the basics of C++ I decided to get her to send me notes / assignments each week so I would have some definite material to work fro...