Most browsers display ordered lists like this:
1. foo
2. bar
3. baz
Is there a way to change the numbering to use a prefix instead:
#1 foo
#2 bar
#3 baz
What's the idiomatic way to do maximumBy (higher order function taking a comparison function for the test), on a list of lists, where the comparison we want to make is the sum of the list, in Python?
Here's a Haskell implementation and example output:
> maximumBy (compare `on` sum) [[1,2,3],[4,5,6],[1,3,5]]
> [4,5,6]
We currently have a form with the standard multi-select functionality of "here are the available options, here are the selected options, here are some buttons to move stuff back and forth." However, the client now wants the ability to not just select certain items, but to also categorize them. For example, given a list of books, they want to not just select the ones they own, but also the ones they've read, the ones they would like to read, and the ones they've heard about. (All examples fictional.) Thankfully, a selected item can only be in one category at a time.
I can find many examples of moving items between listboxes, but not a single one for moving items between multiple listboxes. To add to the complication, the form needs to have two sets of list+categories, e.g. a list of movies that need to be categorized in addition to the aforementioned books.
EDIT: Having now actually sat down to try to code the non-javascripty bits, I need to revise my question, because I realized that multiple select lists won't really work from the "how do I inform the server about all this lovely new information" standpoint. So the html code is now a pseudo-listbox, i.e. an unordered list (ul) displayed in a box with a scrollbar, and each list item (<li>) has a set of five radio buttons (unselected/own/read/like/heard).
My task is still roughly the same: how to take this one list and make it easy to categorize the items, in such a way that the user can tell at a glance what is in what category. (The pseudo-listbox has some of the same disadvantages as a multi-select listbox, namely it's hard to tell what's selected if the list is long enough to scroll.) The dream solution would be a drag-and-drop type thing, but at this point even buttons would be OK.
Another modification (a good one) is that the client has revised the lists, so the longest is now "only" 62 items long (instead of the many hundreds they had before). The categories will still mostly contain zero, one, or two selected items, possibly a couple more if the user was overzealous.
As far as OS and stuff, the site is in classic asp (quit snickering!), the server-side code is VBScript, and so far we've avoided the various Javascript libraries by the simple expedient of almost never using client-side scripting. This one form for this one client is currently the big exception. Give 'em an inch and they want a mile...
Oh, and I have to add: I suck at Javascript, or really at any C-descendant language. Curly braces give me hives. I'd really, really like something I can just copy & paste into my page, maybe tweak some variable names, and never look at it again. A girl can dream, can't she? :)
[existing code deleted because it's largely irrelevant.]
I would like to keep the contents of large UI lists cached on the client, and updated according to criterial or regularly. Client side code can then just fill the dropdowns locally, avoiding long page download times.
How can I go about this? I mean, what patterns and strategies would be suitable for this?
I want to convert a string such as 'a=b,a=c,a=d,b=e' into a dict of lists {'a': ['b', 'c', 'd'], 'b': ['e']} in Python 2.6.
My current solution is this:
def merge(d1, d2):
for k, v in d2.items():
if k in d1:
if type(d1[k]) != type(list()):
d1[k] = list(d1[k])
d1[k].append(v)
else:
d1[k] = list(v)
return d1
record = 'a=b,a=c,a=d,b=e'
print reduce(merge, map(dict,[[x.split('=')] for x in record.split(',')]))
which I'm sure is unnecessarily complicated.
Any better solutions?
Hello,
I have two comma separated lists:-
36,189,47,183,65,50
65,50,189,47
The question is how to compare the two in classic ASP in order to identify and return any values that exist in list 1 but that don't exist in list 2 bearing in mind that associative arrays aren't available.
E.g., in the above example I would need the return value to be 36,183
Thanks
Hello,
I am trying to build a list of lists using the following code:
list=3*[[]]
Now I am trying to append a string to the list in position 0:
list[0].append("hello")
However, instead of receiving the list
[ ["hello"] , [], [] ]
I am receiving the list:
[ ["hello"] ,["hello"] , ["hello"] ]
Am I missing something?
Thanks,
Joel
Im trying to count how many repeated lists there are inside a list. But it doesnt work the same way I could count repeated elements in just a list. Im fairly new to python, so apologies if it sounds too easy.
this is what i did
x= [["coffee", "cola", "juice" "tea" ],["coffee", "cola", "juice" "tea"]
["cola", "coffee", "juice" "tea" ]]
dictt= {}
for item in x:
dictt[item]= dictt.get(item, 0) +1
return(dictt)
i just moved from C to C++, and now work with lists.
i have a class called "message", and i need to have a class called "line",
which should have a list of messages in its properties. as i learned, the object's properties should be initialized in the constructor's initialization list, and i had the "urge" to initialize the messages list in addition to the rest of the properties (some strings and doubles). is that "urge" justified? does the list need to be initialized?
thank you in advance
Hi, does anyone know of an API or where I could get hold of data/script to create a <select> drop down lists for occupation and job type?
Regards,
Phil
Hi,
In Python if I have 2 lists say:
l1 = ['a', 'b', 'c', 'd']
l2 = ['c', 'd', 'e']
is there a way to find out how many elements they have the same. In the case about it would be 2 (c and d)
I know I could just do a nested loop but is there not a built in function like in php with the array_intersect function
Thanks
I'm surprised that I cannot find on the net a solution where I could manage views for content types. Do I really have to visit each task list with my browser to add/modify a view?
Is there any solutions available that would allow me to just define a view for content type and thus make this view available on all lists where content type is?
Hay All.
I have a list which consists of many lists, here is an example
[
[Obj, Obj, Obj, Obj],
[Obj],
[Obj],
[
[Obj,Obj],
[Obj,Obj,Obj]
]
]
Is there a way to join all these items together as 1 list, so the output will be something like
[Obj,Obj,Obj,Obj,Obj,Obj,Obj,Obj,Obj,Obj,Obj]
Thanks
Hello,
In your experience, what is the best web programming language used to handle sorting and comparison of very large lists (ie tens of thousands of email addresses)?
I am most familiar with PHP. I think that it could get the job done, but I'm unsure of other languages and if there might be a bettor suitor.
Thanks!
for documents with lists with pagination, is it better to embed or use
reference? im reading the custom type "SONManipulator" and it appears
to transform every thing on retrieval, even the sub docs.
i want to keep the list in the document sorted, should this impact
anything?
How are lists in python stored internally? Is it an array? A linked list? Something else?
Or does the interpreter guess at the right structure for each instance based on length, etc.
If the question is implementation dependent, what about the classic CPython?
Using the lists webservice I retrieve the items from a list. In the XML returned I can see the attribute ows__IsCurrentVersion="1" which I assume is the same as the file object model (i.e. a boolean to say if it is current or not).
However I do not see a way to identify what revision it is? What should that attribute be?
I have two generic lists, both containing different data, except 4 fields, which I want to compare to another list and find items that do not match in either list.
I need to basically replace where it says equals below, with not equals!
var unMatchedData = from liveLines in liveList
join oldList in comapreSnapshotList
on new {liveLines.ClientNo, liveLines.SequenceNo, liveLines.LineNo, liveLines.Text} equals
new {oldList.ClientNo, oldList.SequenceNo, oldList.LineNo, oldList.Text}
select new KNOWTXTS
{
ClientNo = liveLines.ClientNo,
SequenceNo = liveLines.SequenceNo,
LineNo = liveLines.LineNo,
Text = liveLines.Text
};
I am working on a program where each item can hold an array of items (i'm making a menu, which has a tree-like structure)
currently i have the items as a list, instead of an array, but I don't feel like I'm using it to its full potential to simplify code. I chose a list over a standard array because the interface (.add, .remove, etc...) makes a lot of sense.
I have code to search through the structure and return the path of the name (i.e. Item.subitem.subsubitem.subsubsubitem). Below is my code:
public class Item
{
//public Item[] subitem; <-- Array of Items
public List<Item> subitem; // <-- List of Items
public Color itemColor = Color.FromArgb(50,50,200);
public Rectangle itemSize = new Rectangle(0,0,64,64);
public Bitmap itemBitmap = null;
public string itemName;
public string LocateItem(string searchName)
{
string tItemName = null;
//if the item name matches the search parameter, send it up)
if (itemName == searchName)
{
return itemName;
}
if (subitem != null)
{
//spiral down a level
foreach (Item tSearchItem in subitem)
{
tItemName = tSearchItem.LocateItem(searchName);
if (tItemName != null)
break; //exit for if item was found
}
}
//do name logic (use index numbers)
//if LocateItem of the subitems returned nothing and the current item is not a match, return null (not found)
if (tItemName == null && itemName != searchName)
{
return null;
}
//if it's not the item being searched for and the search item was found, change the string and return it up
if (tItemName != null && itemName != searchName)
{
tItemName.Insert(0, itemName + "."); //insert the parent name on the left --> TopItem.SubItem.SubSubItem.SubSubSubItem
return tItemName;
}
//default not found
return null;
}
}
My question is if there is an easier way to do this with lists? I've been going back and forth in my head as to whether I should use lists or just an array. The only reason I have a list is so that I don't have to make code to resize the array each time I add or remove an item.
I can not figure out why my code does not filter out lists from a predefined list.
I am trying to remove specific list using the following code.
data = [[1,1,1],[1,1,2],[1,2,1],[1,2,2],[2,1,1],[2,1,2],[2,2,1],[2,2,2]]
data = [x for x in data if x[0] != 1 and x[1] != 1]
print data
My result:
data = [[2, 2, 1], [2, 2, 2]]
Expected result:
data = [[1,2,1],[1,2,2],[2,1,1],[2,1,2],[2,2,1],[2,2,2]]
Hello,
I have two comma seperated lists:-
36,189,47,183,65,50
65, 50, 189, 47
the question is how to compare the two in classic ASP in order to identify and return any values that exist in list 1 but that don't exist in list 2 bearing in mind that associative arrays aren't available.
e.g. in the above example I would need the return value to be 36,183
Thanks
I have few lists like:
a = [1, 2, 3, 4, 5]
b = [4, 6, 5, 9, 2]
c = [4, 7, 9, 1, 2]
I want to trim all of them using a loop, instead of doing as below:
a[-2:]
b[-2:]
c[-2:]
I tried but got confused with pass by value or pass by reference fundamentals, looked into other questions as well but no help.
Thanks
createSchedule([[math109]], fall, Out).
[[cs485, cs485], [cs355, cs355, cs462, cs462, cs462], [cs345, cs345, cs352, cs352, cs352, cs362, cs362, cs362, cs396, cs396, cs396], [cs330, cs330, cs330], [cs255, cs255, cs255, cs268, cs268], [math114, cs245, cs245], [math112, cs145, cs146], [math109]]
Out = _G431
this is what prolog returns and the list of lists is shown by using write(Out) in prolog.
Any ideas why it is showing this?
Thanks
I'm having some trouble with the game I started.
http://testing.fyrastudio.com/lab/tweetOlympics/v0.002/
The thing is that i have an athlete running and he must jump at the same time. A race with obstacles.
I have him running (with pressing the letter Q repeateadly). I also have him jumping (with letter P)
But the thing is that when he runs and jumps at the same time, he seems to be jumping at the same place, instead of going forward with the jump... any ideas how can I fix this??
This is the code I'm using for running and jumping on a continuos loop.
//if accelearing and the last time that he accelerated was less than X seconds ago, hes running an accelaring
if (athlete.accelerating && timeCurrent - athlete.last_acceleration > athlete.delay_acceleration) {
athlete.accelerating = false;
athlete.last_acceleration = timeCurrent;
athlete.running = true;
}
if (!athlete.accelerating && timeCurrent - athlete.last_acceleration > athlete.delay_acceleration) {
athlete.decelerating = true;
}
if(athlete.decelerating && timeCurrent - athlete.last_deceleration > athlete.delay_deceleration){
if(athlete.speed >= 1){
//athlete starts to decelarate
athlete.last_deceleration = timeCurrent;
athlete.decelerate();
}else {
athlete.running = false;
}
}
if (athlete.running) {
athlete.position += athlete.speed;
}
if (athlete.jumping) {
if (athlete.jump_height < 1) {
athlete.jump_height = 1;
}else {
if (athlete.jump_height >= athlete.jump_max_height) {
athlete.jump_height = athlete.jump_max_height;
athlete.jumping = false;
}else {
athlete.jump_height = athlete.jump_height * athlete.jump_speed;
}
}
}
if (!athlete.jumping) {
if(athlete.jump_height > 1){
athlete.jump_height = athlete.jump_height * 0.9;
}else {
athlete.jump_height = 1;
}
}
athlete.scaleX = athlete.scaleY = athlete.jump_height;
athlete.x = athlete.position;
Thanks!