Search Results

Search found 4616 results on 185 pages for 'lists'.

Page 17/185 | < Previous Page | 13 14 15 16 17 18 19 20 21 22 23 24  | Next Page >

  • Python - List of Lists Slicing Behavior

    - by Dan Dobint
    When I define a list and try to change a single item like this: list_of_lists = [['a', 'a', 'a'], ['a', 'a', 'a'], ['a', 'a', 'a']] list_of_lists[1][1] = 'b' for row in list_of_lists: print row It works as intended. But when I try to use list comprehension to create the list: row = ['a' for range in xrange(3)] list_of_lists = [row for range in xrange(3)] list_of_lists[1][1] = 'b' for row in list_of_lists: print row It results in an entire column of items in the list being changed. Why is this? How can I achieve the desired effect with list comprehension?

    Read the article

  • Why are references compacted inside Perl lists?

    - by parkan
    Putting a precompiled regex inside two different hashes referenced in a list: my @list = (); my $regex = qr/ABC/; push @list, { 'one' => $regex }; push @list, { 'two' => $regex }; use Data::Dumper; print Dumper(\@list); I'd expect: $VAR1 = [ { 'one' => qr/(?-xism:ABC)/ }, { 'two' => qr/(?-xism:ABC)/ } ]; But instead we get a circular reference: $VAR1 = [ { 'one' => qr/(?-xism:ABC)/ }, { 'two' => $VAR1->[0]{'one'} } ]; This will happen with indefinitely nested hash references and shallowly copied $regex. I'm assuming the basic reason is that precompiled regexes are actually references, and references inside the same list structure are compacted as an optimization (\$scalar behaves the same way). I don't entirely see the utility of doing this (presumably a reference to a reference has the same memory footprint), but maybe there's a reason based on the internal representation Is this the correct behavior? Can I stop it from happening? Aside from probably making GC more difficult, these circular structures create pretty serious headaches. For example, iterating over a list of queries that may sometimes contain the same regular expression will crash the MongoDB driver with a nasty segfault (see https://rt.cpan.org/Public/Bug/Display.html?id=58500)

    Read the article

  • Wicket: How to implement an IDataProvider/LoadableDetachableModel for indexed lists

    - by cretzel
    What's the best way to implement an IDataProvider and a LoadableDetachable in Wicket for an indexed list? Suppose I have a Customer who has a list of Adresses. class Customer { List adresses; } Now I want to implement a data provider/ldm for the adresses of a customer. I suppose the usual way is an IDataProvider as an inner class which refers to the customer model of the component, like: class AdressDataProvider implements IDataProvider { public Iterator iterator() { Customer c = (Customer)Component.this.getModel(); // somehow get the customer model return c.getAdresses().iterator(); } public IModel model(Object o) { Adress a = (Adress) o; // Return an LDM which loads the adress by id. return new AdressLoadableDetachableModel(a.getId()); } } Question: How would I implement this, when the adress does not have an ID (e.g. it's a Hibernate Embeddable/CollectionOfElements) but can only be identified by its index in the customer.adresses list? How do I keep reference to the owning entity and the index? In fact, I know a solution, but I wonder if there's a common pattern to do this.

    Read the article

  • Combining Variable Numbers of Lists w/ LINQ

    - by Anthony Compton
    I have a list (List) of objects. Each of those objects contains a list (List) of strings describing them. I'm needing to create a dropdown containing all of the distinct strings used to describe the objects (Cards). To do this, I need a list of distinct strings used. Any idea how/if this can be done with LINQ?

    Read the article

  • Remove pointer object whose reference is mantained in three different lists

    - by brainydexter
    I am not sure how to approach this problem: 'Player' class mantains a list of Bullet* objects: class Player { protected: std::list< Bullet* > m_pBullet_list; } When the player fires a Bullet, it is added to this list. Also, inside the constructor of bullet, a reference of the same object is updated in CollisionMgr, where CollisionMgr also mantains a list of Bullet*. Bullet::Bullet(GameGL*a_pGameGL, Player*a_pPlayer) : GameObject( a_pGameGL ) { m_pPlayer = a_pPlayer; m_pGameGL->GetCollisionMgr()->AddBullet(this); } class CollisionMgr { void AddBullet(Bullet* a_pBullet); protected: std::list< Bullet*> m_BulletPList; } In CollisionMgr.Update(); based on some conditions, I populate class Cell which again contain a list of Bullet*. Finally, certain conditions qualify a Bullet to be deleted. Now, these conditions are tested upon while iterating through a Cell's list. So, if I have to delete the Bullet object, from all these places, how should I do it so that there are no more dangling references to it? std::list< Bullet*>::iterator bullet_it; for( bullet_it = (a_pCell->m_BulletPList).begin(); bullet_it != (a_pCell->m_BulletPList).end(); bullet_it++) { bool l_Bullet_trash = false; Bullet* bullet1 = *bullet_it; // conditions would set this to true if ( l_Bullet_Trash ) // TrashBullet( bullet1 ); continue; } Also, I was reading about list::remove, and it mentions that it calls the destructor of the object we are trying to delete. Given this info, if I delete from one list, the object does not exist, but the list would still contain a reference to it..How do I handle all these problems ? Can someone please help me here ? Thanks PS: If you want me to post more code or provide explanation, please do let me know.

    Read the article

  • F# Extention Methods on Lists, IEnumberable, etc

    - by flevine100
    I have searched StackOverflow (and other sources) for this answer, but can't seem to find anything. In C#, if I had a widget definition, say: class widget { public string PrettyName() { ... do stuff here } } and I wanted to allow for easy printing of a list of Widgets, I might do this: namespace ExtensionMethods { public static PrintAll( this IEnumerable<Widget> widgets, TextWriter writer ) { foreach(var w in widgets) { writer.WriteLine( w.PrettyName() ) } } } How would I accomplish something similar with a record type and a collection (List or Seq preferrably in F#). I'd love to have a list of Widgest and be able to call a function right on the collection that did something like this. Assume (since it's F#) that the function would not be changing the state of the collection that it's attached to, but returning some new value.

    Read the article

  • Copying 2D lists in python

    - by SuperString
    Hi I want to copy a 2D list, so that if I modify 1 list, the other is not modified. For 1 D list, I just do this: a = [1,2] b = a[:] And now if I modify b, a is not modified. But this doesn't work for 2D list: a = [[1,2],[3,4]] b = a[:] If I modify b, a gets modified as well. How do I fix this?

    Read the article

  • Howto serialize multiple Lists with Jquery

    - by megens
    I have 3 sortable UL's and a simple jquery/javascript <ul class="sortable" id="menu1"> <li id="id_1">whatever</li> <li id="id_2">you</li> </ul> <ul class="sortable" id="menu2"> <li id="id_3">wanne</li> <li id="id_4">put</li> </ul> <ul class="sortable" id="menu3"> <li id="id_5">in</li> <li id="id_6">here</li> </ul> $(function() { $("ul.sortable").sortable({ connectWith: 'ul' }); }); </script> LI's are draggable between UL's How can i serialize this so i get for example menu1[0]=1&menu1[1]=3 Or and array or whatever i can work with to save the state?

    Read the article

  • Emacs cheat sheet that lists equivalents to everyday vim commands

    - by Yktula
    There were two things that I want to know how to do in Emacs (23.2, *nix): Go to the first character after indentation in a line Go to the first character that's the equivalent to a given character (an equivalent to vim's fx command that goes forward until it hits the x character; maybe C-s (incremental search) is the best way to do this) But, I think it would be better if I had a cheat sheet that listed navigational bindings. Maybe Emacs (self-documenting) can do this on it's own. Is there a list of commands that are equivalent to vim's default commands anywhere? How about a list of navigational key-bindings in Emacs?

    Read the article

  • Comparing lists of objects and update

    - by user2915962
    I have a view, passing a LIST of Originals to this method. Before the post happened, i changed some of the properties. I now receive the updated list as a parameter in my method and would like to update the database with these new values. [HttpPost] public ActionResult NewValue(Page model) { var ListOfOriginals = Session.Query<Original>().ToList(); //GETS the objects i want to update listOfOriginals = Model.Pages // Model.page is the new list containing the updated values RavenSession.SaveChanges(); return RedirectToAction("Index"); } When i debug, i can see that listOfOriginals gets the new values. The problem is that i dont know how to update the RavenDB whith these new values. I tried adding this: Session.Store(listOfOriginals) before the SaveChanges() but that resulted in an error. Maybe there is a much better way of doing this?

    Read the article

  • Consing lists with user-defined type in Haskell

    - by user1319603
    I have this type I defined myself: data Item = Book String String String Int -- Title, Author, Year, Qty | Movie String String String Int -- Title, Director, Year, Qty | CD String String String Int deriving Show -- Title, Artist, Year, Qty I've created an empty list all_Items = [] With the following function I am trying to insert a new book of type Item (Book) into the all_Items addBook all_Items = do putStrLn "Enter the title of the book" tit <- getLine putStrLn "Enter the author of the book" aut <- getLine putStrLn "Enter the year this book was published" yr <- getLine putStrLn "Enter quantity of copies for this item in the inventory" qty <- getLine Book tit aut yr (read qty::Int):all_Items return(all_Items) I however am receiving this error: Couldn't match expected type `IO a0' with actual type `[a1]' The error points to the line where I am using the consing operator to add the new book to the list. I can gather that it is a type error but I can't figure out what it is that I am doing wrong and how to fix it. Thanks in Advance!

    Read the article

  • Haskell: Pattern Matching with Lists

    - by user1670032
    I'm trying to make a function that takes in a list, and if one of the elements is negative, then any elements in that list that are equal to its positive counterpart should be changed to 0. Eg, if there is a -2 in a list, then all 2's in that list should be changed to 0. Any ideas why it only works for some cases and not others? I'm not understanding why this is, I've looked it over several times. changeToZero [] = [] changeToZero [x] = [x] changeToZero (x:zs:y:ws) | (x < 0) && ((-1)*(x) == y) = x : zs : 0 : changeToZero ws changeToZero (x:xs) = x : changeToZero xs *Main changeToZero [-1,1,-2,2,-3,3] [-1,1,-2,2,-3,3] *Main changeToZero [-2,1,2,3] [-2,1,0,3] *Main changeToZero [-2,1,2,3,2] [-2,1,0,3,2] *Main changeToZero [1,-2,2,2,1] [1,-2,2,0,1]

    Read the article

  • Generic Lists copying references rather than creating a copiedList

    - by Dean
    I was developing a small function when trying to run an enumerator across a list and then carry out some action. (Below is an idea of what I was trying to do. When trying to remove I got a "Collection cannot be modified" which after I had actually woken up I realised that tempList must have just been assigned myLists reference rather than a copy of myLists. After that I tried to find a way to say tempList = myList.copy However nothing seems to exist?? I ended up writing a small for loop that then just added each item from myLsit into tempList but I would have thought there would have been another mechanism (like clone??) So my question(s): is my assumption about tempList receiving a reference to myList correct How should a list be copied to another list? private myList as List (Of something) sub new() myList.add(new Something) end sub sub myCalledFunction() dim tempList as new List (Of Something) tempList = myList Using i as IEnumerator = myList.getEnumarator while i.moveNext 'if some critria is met then tempList.remove(i.current) end end using end sub

    Read the article

  • extract/slice/reorder lists in (emacs) lisp?

    - by Stephen
    In python, you might do something like i = (0, 3, 2) x = [x+1 for x in range(0,5)] operator.itemgetter(*i)(x) to get (1, 4, 3). In (emacs) lisp, I wrote this function called extract which does something similar, (defun extract (elems seq) (mapcar (lambda (x) (nth x seq)) elems)) (extract '(0 3 2) (number-sequence 1 5)) but I feel like there should be something built in? All I know is first, last, rest, nth, car, cdr... What's the way to go? ~ Thanks in advance ~

    Read the article

  • Working With Feeds and Lists

    - by Nathan Campos
    I'm using a ListView component to list up some informations at a RSS feed, but when the user clicks the row, I want to change into a detailed view of that RSS Item, so far I've done this: function parseFeed(feed) { var html = ""; for(var i = 0; i < feed.items.length && i < 5; i++) { var item = feed.items[i]; var title = item.title; html += "\n<li onClick='goDetailed()'>\n"; html += "<h3><a href='#' class='ui-link-inherit'>" + title + "</a></h3>\n"; html += "<p>" + item.description + "</p>\n"; html += "</li>"; } $("#dList").append(html); $("#dList").listview('refresh'); } function goDetailed() { $.mobile.changePage($('#detailedPage')); } One of my problems is that the Back button won't come back(it does nothing). My other question is how I can pass the item.title, item.description, item.link and item.updated of the selected row(feed item) to some <div data-role="content">'s at the detail page.

    Read the article

  • Recursively created linked lists with a class, C++

    - by Jon Brant
    I'm using C++ to recursively make a hexagonal grid (using a multiply linked list style). I've got it set up to create neighboring tiles easily, but because I'm doing it recursively, I can only really create all 6 neighbors for a given tile. Obviously, this is causing duplicate tiles to be created and I'm trying to get rid of them in some way. Because I'm using a class, checking for null pointers doesn't seem to work. It's either failing to convert from my Tile class to and int, or somehow converting it but not doing it properly. I'm explicitly setting all pointers to NULL upon creation, and when I check to see if it still is, it says it's not even though I never touched it since initialization. Is there a specific way I'm supposed to do this? I can't even traverse the grid without NULLs of some kind Here's some of my relevant code. Yes, I know it's embarassing. Tile class header: class Tile { public: Tile(void); Tile(char *Filename); ~Tile(void); void show(void); bool LoadGLTextures(); void makeDisplayList(); void BindTexture(); void setFilename(char *newName); char Filename[100]; GLuint texture[2]; GLuint displayList; Tile *neighbor[6]; float xPos, yPos,zPos; };` Tile Initialization: Tile::Tile(void) { xPos=0.0f; yPos=0.0f; zPos=0.0f; glEnable(GL_DEPTH_TEST); strcpy(Filename, strcpy(Filename, "Data/BlueTile.bmp")); if(!BuildTexture(Filename, texture[0]))MessageBox(NULL,"Texture failed to load!","Crap!",MB_OK|MB_ICONASTERISK); for(int x=0;x<6;x++) { neighbor[x]=NULL; } } Creation of neighboring tiles: void MakeNeighbors(Tile *InputTile, int stacks) { for(int x=0;x<6;x++) { InputTile->neighbor[x]=new Tile();InputTile->neighbor[x]->xPos=0.0f;InputTile->neighbor[x]->yPos=0.0f;InputTile->zPos=float(stacks); } if(stacks) { for(int x=0;x<6;x++)MakeNeighbors(InputTile->neighbor[x],stacks-1); } } And finally, traversing the grid: void TraverseGrid(Tile *inputTile) { Tile *temp; for(int x=0;x<6;x++) if(inputTile->neighbor[x]) { temp=inputTile->neighbor[x]; temp->xPos=0.0f; TraverseGrid(temp); //MessageBox(NULL,"Not Null!","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); } } The key line is "if(inputTile-neighbor[x])" and whether I make it "if(inputTile-neighbor[x]==NULL)" or whatever I do, it just isn't handling it properly. Oh and I'm also aware that I haven't set up the list fully. It's only one direction now.

    Read the article

  • Compare 2 lists in MbUnit 3.1

    - by Longball27
    Hi I am trying to compare 2 Dictionary objects for equality in MbUnit 3.1 like so Assert.AreEqual<FieldList>(expectedOutputFieldList, actualOutputFieldList); Where FieldList is = Dictionary<string, object> However this throws up the following "error": Both values look the same when formatted but they are distinct instances. Is there any method for comparing object data rather than instances? Thanks in advance...

    Read the article

  • Arrays/Lists and computing hashvalues (VB, C#)

    - by Jeffrey Kern
    I feel bad asking this question but I am currently not able to program and test this as I'm writing this on my cell-phone and not on my dev machine :P (Easy rep points if someone answers! XD ) Anyway, I've had experience with using hashvalues from String objects. E.g., if I have StringA and StringB both equal to "foo", they'll both compute out the same hashvalue, because they're set to equal values. Now what if I have a List, with T being a native data type. If I tried to compute the hashvalue of ListA and ListB, assuming that they'd both be the same size and contain the same information, wouldn't they have equal hashvalues as well? Assuming as sample dataset of 'byte' with a length of 5 {5,2,0,1,3}

    Read the article

  • How to count children from different lists? [jQuery]

    - by Filip Breckx
    Hi, I'm trying to count the number of child elements a certain category has. This is the situation: <ul id="select_cat"> <li id="_1">Category 1 (<span>#</span>)</li> <li id="_2">Category 2 (<span>#</span>)</li> </ul> <ul id="cat_1> <li>Link 1</li> <li>Link 2</li> <li>Link 3</li> </ul> <ul id="cat_2"> <li>Link 1</li> <li>Link 2</li> </ul> So I want to count the number of children a category has. In this example the first cardinal sign should be 3, and the second should be 2. How can I do this, using jQuery. Check an example (not jQuery) Thanks!

    Read the article

  • Changing style of latex description lists.

    - by Halpo
    This should be an easy question for someone out there. I have a description list \begin{description} \item[Name:] Halpo \item[Email Address:] [email protected] \item[Address:] 1234 Ivy Ln \\ Springfield, USA \end{description} It comes back as Name: Halpo Email Address: [email protected] Address: 1234 Ivy Ln Springfield, USA This is for an official document that has style requirements. The First thing is how do I turn off the bold? second how do I have all the text line up with the item labels and still be left justified?

    Read the article

  • Accessing generic lists with delegate notation

    - by n0vic3c0d3r
    I see some people write: //wordList is List<string> wordList.ForEach(delegate(string word){ Console.WriteLine(word);}); instead of: foreach(string word in wordList) { Console.WriteLine(word); } What is the advantage in doing so. Also I couldn't fathom the Action delegate syntax given above though I have used delegates in C# 2.0. Basically I am not able to relate the syntax with the concept of delegates I am familiar with. Can you please help me understand the syntax. Is it some shorthand?

    Read the article

< Previous Page | 13 14 15 16 17 18 19 20 21 22 23 24  | Next Page >