Search Results

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

Page 24/185 | < Previous Page | 20 21 22 23 24 25 26 27 28 29 30 31  | Next Page >

  • Noob Python Question: List Confusion

    - by potatocubed
    I'm trying to transfer the contents of one list to another, but it's not working and I don't know why not. My code looks like this: list1 = [1, 2, 3, 4, 5, 6] list2 = [] for item in list1: list2.append(item) list1.remove(item) But if I run it my output looks like this: >>> list1 [2, 4, 6] >>> list2 [1, 3, 5] My question is threefold, I guess: Why is this happening, how do I make it work, and am I overlooking an incredibly simple solution like a 'move' statement or something?

    Read the article

  • How to get a List ordered by the List it's filtered by?

    - by DaveDev
    I have a method as follows. It returns a list of MyTypes which appear to be ordered by myType.Id ascending by default. public List<MyType> GetMyTypes(List<int> ids) { return (from myType in db.MyTypes where ids.Contains(myType.Id) select new MyType { MyValue = myType.MyValue }).ToList(); } So if ids contains 302 300 301 the List returned contains items in ascending order. What do I need to do to return List<MyType> in the order of ids? Thanks edit: I've tried orderby ids.IndexOf(myType.Id) but it throws the exception Method 'Int32 IndexOf(Int32)' has no supported translation to SQL.

    Read the article

  • There is no web named - Sharepoint Event Hander

    - by Roosh Malai
    I activated following code with feature (web level scope). Now when i add an item to any document library it should create a folder "". No folder is created and no error is given either. can anyone see what's is going on? I got the following from the log file. I found similar code all over google so I am kinda puzzled why is not working in my environment. Thanks using System; using System.Collections.Generic; using System.Text; using Microsoft.SharePoint; namespace AddaFolder { class clAddaFolder : SPItemEventReceiver { public override void ItemAdded(SPItemEventProperties properties) { base.ItemAdded(properties); using (SPSite currentSite = new SPSite(SPContext.Current.Site.Url)) using (SPWeb currentWeb = currentSite.OpenWeb(SPContext.Current.Web.Url)) { try { //SPListTemplateCollection coll = currentWeb.ListTemplates; //Get the current document library link SPList newList = currentWeb.GetList(SPContext.Current.Web.Url); //.Site.Url); //newList = currentWeb.Lists.Add("My TEST Folder",SPFileSystemObjectType.Folder); //newList.Lists.Items.Add("My TEST Folder", SPFileSystemObjectType.Folder); //newList.Update(); SPListItem newListItem; //newListItem = newList.Folders.Add("", SPFileSystemObjectType.Folder, "My Test Folder"); newListItem = newList.Folders.Add(newList.ToString(), SPFileSystemObjectType.Folder, "My Test Folder"); newListItem.Update(); } catch (SPException spEx) { throw spEx; } } } } } 04/03/2010 17:52:44.25 w3wp.exe (0x00C0) 0x0C88 Windows SharePoint Services General 8kh7 High There is no Web named "/sites/myDevSiteColl/myDevWeb/Shared Documents/Forms/AllItems.aspx". 04/03/2010 17:52:44.26 w3wp.exe (0x00C0) 0x0C88 Windows SharePoint Services General 8kh7 High There is no Web named "/sites/myDevSiteColl/myDevWeb/My TEST Doc Library/Forms/AllItems.aspx". 04/03/2010 17:52:44.27 w3wp.exe (0x00C0) 0x0C88 Windows SharePoint Services General 8kh7 High There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Calendar/calendar.aspx". 04/03/2010 17:52:44.29 w3wp.exe (0x00C0) 0x0C88 Windows SharePoint Services General 8kh7 High There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Tasks/AllItems.aspx". 04/03/2010 17:52:44.30 w3wp.exe (0x00C0) 0x0C88 Windows SharePoint Services General 8kh7 High There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Team Discussion/AllItems.aspx". 04/03/2010 17:52:44.31 w3wp.exe (0x00C0) 0x0C88 Windows SharePoint Services General 8kh7 High There is no Web named "/sites/myDevSiteColl/myDevWeb/Shared Documents/Forms/AllItems.aspx". 04/03/2010 17:52:44.32 w3wp.exe (0x00C0) 0x0C88 Windows SharePoint Services General 8kh7 High There is no Web named "/sites/myDevSiteColl/myDevWeb/My TEST Doc Library/Forms/AllItems.aspx". 04/03/2010 17:52:44.34 w3wp.exe (0x00C0) 0x0C88 Windows SharePoint Services General 8kh7 High There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Calendar/calendar.aspx". 04/03/2010 17:52:44.35 w3wp.exe (0x00C0) 0x0C88 Windows SharePoint Services General 8kh7 High There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Tasks/AllItems.aspx". 04/03/2010 17:52:44.36 w3wp.exe (0x00C0) 0x0C88 Windows SharePoint Services General 8kh7 High There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Team Discussion/AllItems.aspx". 04/03/2010 17:52:51.33 w3wp.exe (0x00C0) 0x0C88 Windows SharePoint Services General 8kh7 High There is no Web named "/sites/myDevSiteColl/myDevWeb/Shared Documents/Forms/AllItems.aspx". 04/03/2010 17:52:51.34 w3wp.exe (0x00C0) 0x0C88 Windows SharePoint Services General 8kh7 High There is no Web named "/sites/myDevSiteColl/myDevWeb/My TEST Doc Library/Forms/AllItems.aspx". 04/03/2010 17:52:51.35 w3wp.exe (0x00C0) 0x0C88 Windows SharePoint Services General 8kh7 High There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Calendar/calendar.aspx". 04/03/2010 17:52:51.37 w3wp.exe (0x00C0) 0x0C88 Windows SharePoint Services General 8kh7 High There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Tasks/AllItems.aspx". 04/03/2010 17:52:51.38 w3wp.exe (0x00C0) 0x0C88 Windows SharePoint Services General 8kh7 High There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Team Discussion/AllItems.aspx". 04/03/2010 17:52:51.39 w3wp.exe (0x00C0) 0x0C88 Windows SharePoint Services General 8kh7 High There is no Web named "/sites/myDevSiteColl/myDevWeb/Shared Documents/Forms/AllItems.aspx". 04/03/2010 17:52:51.40 w3wp.exe (0x00C0) 0x0C88 Windows SharePoint Services General 8kh7 High There is no Web named "/sites/myDevSiteColl/myDevWeb/My TEST Doc Library/Forms/AllItems.aspx". 04/03/2010 17:52:51.41 w3wp.exe (0x00C0) 0x0C88 Windows SharePoint Services General 8kh7 High There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Calendar/calendar.aspx". 04/03/2010 17:52:51.43 w3wp.exe (0x00C0) 0x0C88 Windows SharePoint Services General 8kh7 High There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Tasks/AllItems.aspx". 04/03/2010 17:52:51.44 w3wp.exe (0x00C0) 0x0C88 Windows SharePoint Services General 8kh7 High There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Team Discussion/AllItems.aspx". 04/03/2010 17:53:02.69 w3wp.exe (0x00C0) 0x0C88 Windows SharePoint Services General 8kh7 High There is no Web named "/sites/myDevSiteColl/myDevWeb/Shared Documents/Forms/AllItems.aspx". 04/03/2010 17:53:02.71 w3wp.exe (0x00C0) 0x0C88 Windows SharePoint Services General 8kh7 High There is no Web named "/sites/myDevSiteColl/myDevWeb/My TEST Doc Library/Forms/AllItems.aspx". 04/03/2010 17:53:02.72 w3wp.exe (0x00C0) 0x0C88 Windows SharePoint Services General 8kh7 High There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Calendar/calendar.aspx". 04/03/2010 17:53:02.73 w3wp.exe (0x00C0) 0x0C88 Windows SharePoint Services General 8kh7 High There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Tasks/AllItems.aspx". 04/03/2010 17:53:02.74 w3wp.exe (0x00C0) 0x0C88 Windows SharePoint Services General 8kh7 High There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Team Discussion/AllItems.aspx". 04/03/2010 17:53:02.75 w3wp.exe (0x00C0) 0x0C88 Windows SharePoint Services General 8kh7 High There is no Web named "/sites/myDevSiteColl/myDevWeb/Shared Documents/Forms/AllItems.aspx". 04/03/2010 17:53:02.76 w3wp.exe (0x00C0) 0x0C88 Windows SharePoint Services General 8kh7 High There is no Web named "/sites/myDevSiteColl/myDevWeb/My TEST Doc Library/Forms/AllItems.aspx". 04/03/2010 17:53:02.77 w3wp.exe (0x00C0) 0x0C88 Windows SharePoint Services General 8kh7 High There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Calendar/calendar.aspx". 04/03/2010 17:53:02.78 w3wp.exe (0x00C0) 0x0C88 Windows SharePoint Services General 8kh7 High There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Tasks/AllItems.aspx". 04/03/2010 17:53:02.79 w3wp.exe (0x00C0) 0x0C88 Windows SharePoint Services General 8kh7 High There is no Web named "/sites/myDevSiteColl/myDevWeb/Lists/Team Discussion/AllItems.aspx".

    Read the article

  • sudo apt-get update error

    - by Kapil Anand
    I got the following error Reading package lists... Done W: GPG error: http://extras.ubuntu.com oneiric Release: Unknown error executing gpgv executing gpgv ---- W: GPG error: http://archive.ubuntu.com oneiric-updates Release: Unknown error executing gpgv Then after googling it i found and followed the following but that caused one error **sudo -i apt-get clean cd /var/lib/apt mv lists lists.old mkdir -p lists/partial apt-get clean apt-get update** while running i got the error " kapil@ubuntu:/var/lib/apt$ sudo mv lists lists.old mv: cannot move `lists' to `lists.old/lists': Directory not empty " so once again running the update command I got the same error again. Please help me what should i do?

    Read the article

  • Is there a better way to handle data abstraction in this example?

    - by sigil
    I'm building an application that retrieves Sharepoint list data via a web service SPlists.Lists. To create an instance of the web service, I have the following class: class SharepointServiceCreator { public SPlists.Lists createService() { listsService.Url = "http://wss/sites/SPLists/_vti_bin/lists.asmx"; listsService.Credentials = System.Net.CredentialCache.DefaultCredentials; SPlists.Lists listsService=new SPlists.Lists(); } } I'm concerned that this isn't good OOP abstraction, though, because in order to create this service elsewhere in my application, I would need the following code: class someClass { public void someMethod() { SharepointServiceCreator s=new SharepointServiceCreator() SPlists.Lists listService=s.createService() } } Having to use declare the instance of listService in someMethod as type SPlists.Lists seems wrong, because it means that someClass needs to know about how SharepointServiceCreator is implemented. Or is this ok?

    Read the article

  • Why does using cons to create a pair of two lists produce a list and two elements?

    - by fingerprint211b
    I've started learning Scheme, for fun mostly, and because I've never used a functional language before. I chose Scheme because I wanted to read SICP for a long time. Anyway, I'm currently learning about lists, and before that I learned about cons, car and cdr. And there's an example that creates a list of lists with cons, like this : (cons (list 1 2) (list 3 4)) The resulting list is ((1 2) 3 4), which doesn't make sense to me, I would expect ((1 2)(3 4)) to be the result (a list made out of two lists). Why does it behave like that? I realize that if I were to use car, I would get (1 2), and cdr I'd get (3 4) becaue cdr always returns "the rest", but I don't understand why the list isn't made of two lists?

    Read the article

  • python: How to refer to specific item within a list of lists?

    - by user964689
    Python beginner here, I have a list of lists and want to refer to a specific part of that list. For example lol = [[1, 2, 4], [6, 7, 8], [9, 10, 14]] If I just want to print the first item in one of the lists, eg the 1, 6 or 9, how would I do that? I can only find ways to refer to each of the lists seperately eg lol[0] but not to then refer to an item within that list. Thank you in advance for your help! Cheers

    Read the article

  • If Scheme is untyped, how can it have numbers and lists?

    - by Dokkat
    Scheme is said to be just an extension of the Untyped Lambda Calculus (correct me if I am wrong). If that is the case, how can it have Lists and Numbers? Those, to me, look like 2 base types. So I'd say Racket is actually an extension of the Simply Typed Lambda Calculus. No? Question: Is Scheme's type system actually based or more similar to Simply Typed or Untyped Lambda Calculus? In what ways does it differ from Untyped and or Simply Typed Lambda Calculus? (The same question is valid for "untyped" languages such as Python and JavaScript - all of which look like they have base types to me.)

    Read the article

  • Why won't apt-get install anything after I deleted its cached lists?

    - by Gernot
    Recently I had a problem with the update-manager and search for a solution. On my search I found a post, where someone had the same problem and as solution they told him he should run this command on the terminal: sudo rm /var/lib/apt/lists/* I also run this, and the update-manager worked again. But now, I noticed that apt-get won't install anything. I wanted to install rvm (for ruby) and therefore I needed a few packages (build-essential and curl to be precise). But if I tried to install them, I always get the message that there is no installcandidate for that package... . What can I do to get apt-get working again?

    Read the article

  • Grub2 mutual dependency issue

    - by A T
    For various reasons I am installing .deb dependencies for grub2 using dpkg directly (rather than apt-get). root@ubuntu:/dl# dpkg -i grub-gfxpayload-lists_0.6_amd64.deb Selecting previously unselected package grub-gfxpayload-lists. (Reading database ... 249808 files and directories currently installed.) Preparing to unpack grub-gfxpayload-lists_0.6_amd64.deb ... Unpacking grub-gfxpayload-lists (0.6) ... dpkg: dependency problems prevent configuration of grub-gfxpayload-lists: grub-gfxpayload-lists depends on grub-pc (>= 1.99~20101210-1ubuntu2); however: Package grub-pc is not configured yet. dpkg: error processing package grub-gfxpayload-lists (--install): dependency problems - leaving unconfigured Processing triggers for man-db (2.6.7.1-1) ... Errors were encountered while processing: grub-gfxpayload-lists By configure I assume it means install+configure, so I tried: root@ubuntu:/dl# dpkg -i grub-pc_2.02~beta2-9_amd64.deb (Reading database ... 249818 files and directories currently installed.) Preparing to unpack grub-pc_2.02~beta2-9_amd64.deb ... Unpacking grub-pc (2.02~beta2-9) over (2.02~beta2-9) ... dpkg: dependency problems prevent configuration of grub-pc: grub-pc depends on grub2-common (= 2.02~beta2-9); however: Package grub2-common is not installed. grub-pc depends on grub-pc-bin (= 2.02~beta2-9); however: Package grub-pc-bin is not installed. grub-pc depends on grub-gfxpayload-lists; however: Package grub-gfxpayload-lists is not configured yet. dpkg: error processing package grub-pc (--install): dependency problems - leaving unconfigured Processing triggers for man-db (2.6.7.1-1) ... Errors were encountered while processing: grub-pc How do I solve this problem?

    Read the article

  • Efficient and accurate way to compact and compare Python lists?

    - by daveslab
    Hi folks, I'm trying to a somewhat sophisticated diff between individual rows in two CSV files. I need to ensure that a row from one file does not appear in the other file, but I am given no guarantee of the order of the rows in either file. As a starting point, I've been trying to compare the hashes of the string representations of the rows (i.e. Python lists). For example: import csv hashes = [] for row in csv.reader(open('old.csv','rb')): hashes.append( hash(str(row)) ) for row in csv.reader(open('new.csv','rb')): if hash(str(row)) not in hashes: print 'Not found' But this is failing miserably. I am constrained by artificially imposed memory limits that I cannot change, and thusly I went with the hashes instead of storing and comparing the lists directly. Some of the files I am comparing can be hundreds of megabytes in size. Any ideas for a way to accurately compress Python lists so that they can be compared in terms of simple equality to other lists? I.e. a hashing system that actually works? Bonus points: why didn't the above method work?

    Read the article

  • Why do I have two different DNS suffix lists?

    - by Rob Kennedy
    My Windows XP laptop has two different DNS suffix lists. The first is the one I see by selecting the Properties dialog of any of my network connections, selecting Internet Protocol Properties Advanced DNS tab, and looking at the list under the "Append these DNS suffixes (in order)" option. The second list is the one shown under "DNS Suffix Search List" when I run ipconfig /all. As far as I can tell, only the second list ever gets used to resolve unqualified host names. Why are there two different lists? How do I configure the second list? Or how can I make my computer use the first list?

    Read the article

  • How do you write multiple lists from Matlab to the same excel file?

    - by Ben Fossen
    I have several lists in Matlab that I want to write to the same excel file. I have one list xordered and another list aspl. I do not know the length of the lists till after I run the Matlab program. I used data = xlswrite('edgar.xls',fliplr(sortedx'),'A2:A3000') for the first list but when I tried to write another list to the same file like this I ended up with two different excel files named edgar.xls asp_data = xlswrite('edagr.xls', fliplr(aspl'), 'B2:B3000') Is there a way I can write both of these lists into the same excel file? xordered in the A column and aspl in the B column?

    Read the article

  • Algorithm to find a measurement of similarity between lists.

    - by Cubed
    Given that I have two lists that each contain a separate subset of a common superset, is there an algorithm to give me a similarity measurement? Example: A = { John, Mary, Kate, Peter } and B = { Peter, James, Mary, Kate } How similar are these two lists? Note that I do not know all elements of the common superset. Update: I was unclear and I have probably used the word 'set' in a sloppy fashion. My apologies. Clarification: Order is of importance. If identical elements occupy the same position in the list, we have the highest similarity for that element. The similarity decreased the farther apart the identical elements are. The similarity is even lower if the element only exists in one of the lists. I could even add the extra dimension that lower indices are of greater value, so a a[1] == b[1] is worth more than a[9] == b[9], but that is mainly cause I am curious.

    Read the article

  • How can I merge two lists and sort them working in 'linear' time?

    - by Sergio Tapia
    I have this, and it works: # E. Given two lists sorted in increasing order, create and return a merged # list of all the elements in sorted order. You may modify the passed in lists. # Ideally, the solution should work in "linear" time, making a single # pass of both lists. def linear_merge(list1, list2): finalList = [] for item in list1: finalList.append(item) for item in list2: finalList.append(item) finalList.sort() return finalList # +++your code here+++ return But, I'd really like to learn this stuff well. :) What does 'linear' time mean?

    Read the article

  • Why are web developers so keen to use lists ?

    - by Bob
    I've been developing for a while and often develop sites using menu tabs. And I can't figure out why so many web developers like using lists < ul < li etc rather than just using plain old divs. I can make menus in divs which are simple and work perfectly in every browser. With lists, I'm usually trying to hack it one way or another to get it work properly. So my question is simple : why should I use lists to create my menus instead of divs ?

    Read the article

  • JUnit Theories: Why can't I use Lists (instead of arrays) as DataPoints?

    - by MatrixFrog
    I've started using the new(ish) JUnit Theories feature for parameterizing tests. If your Theory is set up to take, for example, an Integer argument, the Theories test runner picks up any Integers marked with @DataPoint: @DataPoint public static Integer number = 0; as well as any Integers in arrays: @DataPoints public static Integer[] numbers = {1, 2, 3}; or even methods that return arrays like: @DataPoints public static Integer[] moreNumbers() { return new Integer[] {4, 5, 6};}; but not in Lists. The following does not work: @DataPoints public static List<Integer> numberList = Arrays.asList(7, 8, 9); Am I doing something wrong, or do Lists really not work? Was it a conscious design choice not to allow the use Lists as data points, or is that just a feature that hasn't been implemented yet? Are there plans to implement it in a future version of JUnit?

    Read the article

  • Ubuntu Software Center will not load and cannot be removed

    - by Drew Z.
    My Ubuntu Software Center has stopped working and I have been trying to uninstall/re-install it. This is the error that I repeatedly keep receiving: drew@drew-Aspire-5750:~$ sudo apt-get remove software-center [sudo] password for drew: Reading package lists... Error! E: Encountered a section with no Package: header E: Problem with MergeList /var/lib/apt/lists/dl.google.com_linux_chrome_deb_dists_stable_main_binary-i386_Packages E: The package lists or status file could not be parsed or opened. drew@drew-Aspire-5750:~$ sudo apt-get autoremove software-center Reading package lists... Error! E: Encountered a section with no Package: header E: Problem with MergeList /var/lib/apt/lists/dl.google.com_linux_chrome_deb_dists_stable_main_binary-i386_Packages E: The package lists or status file could not be parsed or opened. drew@drew-Aspire-5750:~$ Any help would be gratefully appreciated.

    Read the article

  • how to speed up the code??

    - by kaushik
    i have very huge code about 600 lines plus. cant post the whole thing here. but a particular code snippet is taking so much time,leading to problems. here i post that part of code please tell me what to do speed up the processing.. please suggest the part which may be the reason and measure to improve them if this small part of code is understandable. using_data={} def join_cost(a , b): global using_data #print a #print b save_a=[] save_b=[] print 1 #for i in range(len(m)): #if str(m[i][0])==str(a): save_a=database_index[a] #for i in range(len(m)): # if str(m[i][0])==str(b): #print 'save_a',save_a #print 'save_b',save_b print 2 save_b=database_index[b] using_data[save_a[0]]=save_a s=str(save_a[1]).replace('phone','text') s=str(s)+'.pm' p=os.path.join("c:/begpython/wavnk/",s) x=open(p , 'r') print 3 for i in range(6): x.readline() k2='a' j=0 o=[] while k2 is not '': k2=x.readline() k2=k2.rstrip('\n') oj=k2.split(' ') o=o+[oj] #print o[j] j=j+1 #print j #print o[2][0] temp=long(1232332) end_time=save_a[4] #print end_time k=(j-1) for i in range(k): diff=float(o[i][0])-float(end_time) if diff<0: diff=diff*(-1) if temp>diff: temp=diff pm_row=i #print pm_row #print temp #print o[pm_row] #pm_row=3 q=[] print 4 l=str(p).replace('.pm','.mcep') z=open(l ,'r') for i in range(pm_row): z.readline() k3=z.readline() k3=k3.rstrip('\n') q=k3.split(' ') #print q print 5 s=str(save_b[1]).replace('phone','text') s=str(s)+'.pm' p=os.path.join("c:/begpython/wavnk/",s) x=open(p , 'r') for i in range(6): x.readline() k2='a' j=0 o=[] while k2 is not '': k2=x.readline() k2=k2.rstrip('\n') oj=k2.split(' ') o=o+[oj] #print o[j] j=j+1 #print j #print o[2][0] temp=long(1232332) strt_time=save_b[3] #print strt_time k=(j-1) for i in range(k): diff=float(o[i][0])-float(strt_time) if diff<0: diff=diff*(-1) if temp>diff: temp=diff pm_row=i #print pm_row #print temp #print o[pm_row] #pm_row=3 w=[] l=str(p).replace('.pm','.mcep') z=open(l ,'r') for i in range(pm_row): z.readline() k3=z.readline() k3=k3.rstrip('\n') w=k3.split(' ') #print w cost=0 for i in range(12): #print q[i] #print w[i] h=float(q[i])-float(w[i]) cost=cost+math.pow(h,2) j_cost=math.sqrt(cost) #print cost return j_cost def target_cost(a , b): a=(b+1)*3 b=(a+1)*2 t_cost=(a+b)*5/2 return t_cost r1='shht:ra_77' r2='grx_18' g=[] nodes=[] nodes=nodes+[[r1]] for i in range(len(y_in_db_format)): g=y_in_db_format[i] #print g #print g[0] g.remove(str(g[0])) nodes=nodes+[g] nodes=nodes+[[r2]] print nodes print "lenght of nodes",len(nodes) lists=[] #lists=lists+[r1] for i in range(len(nodes)): for j in range(len(nodes[i])): lists=lists+[nodes[i][j]] #lists=lists+[r2] print lists distance={} for i in range(len(lists)): if i==0: distance[str(lists[i])]=0 else: distance[str(lists[i])]=long(123231223) #print distance group_dist=[] infinity=long(123232323) for i in range(len(nodes)): distances=[] for j in range(len(nodes[i])): #distances=[] if i==0: distances=distances+[[nodes[i][j], 0]] else: distances=distances+[[nodes[i][j],infinity]] group_dist=group_dist+[distances] #print distances print "group_distances",group_dist #print "check",group_dist[0][0][1] #costs={} #for i in range(len(lists)): #if i==0: # costs[str(lists[i])]=1 #else: # costs[str(lists[i])]=get_selfcost(lists[i]) path=[] for i in range(len(nodes)): mini=[] if i!=(len(nodes)-1): #temp=long(123234324) #Now calculate the cost between the current node and each of its neighbour for k in range(len(nodes[(i+1)])): for j in range(len(nodes[i])): current=nodes[i][j] #print "current_node",current j_distance=join_cost( current , nodes[i+1][k]) #t_distance=target_cost( current , nodes[i+1][k]) t_distance=34 #print distance #print "distance between current and neighbours",distance total_distance=(.5*(float(group_dist[i][j][1])+float(j_distance))+.5*(float(t_distance))) #print "total distance between the intial_nodes and current neighbour",total_distance if int(group_dist[i+1][k][1]) > int(total_distance): group_dist[i+1][k][1]=total_distance #print "updated distance",group_dist[i+1][k][1] a=current #print "the neighbour",nodes[i+1][k],"updated the value",a mini=mini+[[str(nodes[i+1][k]),a]] print mini

    Read the article

  • What's the standard algorithm for syncing two lists of objects?

    - by Oliver Giesen
    I'm pretty sure this must be in some kind of text book (or more likely in all of them) but I seem to be using the wrong keywords to search for it... :( A common task I'm facing while programming is that I am dealing with lists of objects from different sources which I need to keep in sync somehow. Typically there's some sort of "master list" e.g. returned by some external API and then a list of objects I create myself each of which corresponds to an object in the master list. Sometimes the nature of the external API will not allow me to do a live sync: For instance the external list might not implement notifications about items being added or removed or it might notify me but not give me a reference to the actual item that was added or removed. Furthermore, refreshing the external list might return a completely new set of instances even though they still represent the same information so simply storing references to the external objects might also not always be feasible. Another characteristic of the problem is that both lists cannot be sorted in any meaningful way. You should also assume that initializing new objects in the "slave list" is expensive, i.e. simply clearing and rebuilding it from scratch is not an option. So how would I typically tackle this? What's the name of the algorithm I should google for? In the past I have implemented this in various ways (see below for an example) but it always felt like there should be a cleaner and more efficient way. Here's an example approach: Iterate over the master list Look up each item in the "slave list" Add items that do not yet exist Somehow keep track of items that already exist in both lists (e.g. by tagging them or keeping yet another list) When done iterate once more over the slave list Remove all objects that have not been tagged (see 4.) Update Thanks for all your responses so far! I will need some time to look at the links. Maybe one more thing worthy of note: In many of the situations where I needed this the implementation of the "master list" is completely hidden from me. In the most extreme cases the only access I might have to the master list might be a COM-interface that exposes nothing but GetFirst-, GetNext-style methods. I'm mentioning this because of the suggestions to either sort the list or to subclass it both of which is unfortunately not practical in these cases unless I copy the elements into a list of my own and I don't think that would be very efficient. I also might not have made it clear enough that the elements in the two lists are of different types, i.e. not assignment-compatible: Especially, the elements in the master list might be available as interface references only.

    Read the article

  • Of these 3 methods for reading linked lists from shared memory, why is the 3rd fastest?

    - by Joseph Garvin
    I have a 'server' program that updates many linked lists in shared memory in response to external events. I want client programs to notice an update on any of the lists as quickly as possible (lowest latency). The server marks a linked list's node's state_ as FILLED once its data is filled in and its next pointer has been set to a valid location. Until then, its state_ is NOT_FILLED_YET. I am using memory barriers to make sure that clients don't see the state_ as FILLED before the data within is actually ready (and it seems to work, I never see corrupt data). Also, state_ is volatile to be sure the compiler doesn't lift the client's checking of it out of loops. Keeping the server code exactly the same, I've come up with 3 different methods for the client to scan the linked lists for changes. The question is: Why is the 3rd method fastest? Method 1: Round robin over all the linked lists (called 'channels') continuously, looking to see if any nodes have changed to 'FILLED': void method_one() { std::vector<Data*> channel_cursors; for(ChannelList::iterator i = channel_list.begin(); i != channel_list.end(); ++i) { Data* current_item = static_cast<Data*>(i->get(segment)->tail_.get(segment)); channel_cursors.push_back(current_item); } while(true) { for(std::size_t i = 0; i < channel_list.size(); ++i) { Data* current_item = channel_cursors[i]; ACQUIRE_MEMORY_BARRIER; if(current_item->state_ == NOT_FILLED_YET) { continue; } log_latency(current_item->tv_sec_, current_item->tv_usec_); channel_cursors[i] = static_cast<Data*>(current_item->next_.get(segment)); } } } Method 1 gave very low latency when then number of channels was small. But when the number of channels grew (250K+) it became very slow because of looping over all the channels. So I tried... Method 2: Give each linked list an ID. Keep a separate 'update list' to the side. Every time one of the linked lists is updated, push its ID on to the update list. Now we just need to monitor the single update list, and check the IDs we get from it. void method_two() { std::vector<Data*> channel_cursors; for(ChannelList::iterator i = channel_list.begin(); i != channel_list.end(); ++i) { Data* current_item = static_cast<Data*>(i->get(segment)->tail_.get(segment)); channel_cursors.push_back(current_item); } UpdateID* update_cursor = static_cast<UpdateID*>(update_channel.tail_.get(segment)); while(true) { if(update_cursor->state_ == NOT_FILLED_YET) { continue; } ::uint32_t update_id = update_cursor->list_id_; Data* current_item = channel_cursors[update_id]; if(current_item->state_ == NOT_FILLED_YET) { std::cerr << "This should never print." << std::endl; // it doesn't continue; } log_latency(current_item->tv_sec_, current_item->tv_usec_); channel_cursors[update_id] = static_cast<Data*>(current_item->next_.get(segment)); update_cursor = static_cast<UpdateID*>(update_cursor->next_.get(segment)); } } Method 2 gave TERRIBLE latency. Whereas Method 1 might give under 10us latency, Method 2 would inexplicably often given 8ms latency! Using gettimeofday it appears that the change in update_cursor-state_ was very slow to propogate from the server's view to the client's (I'm on a multicore box, so I assume the delay is due to cache). So I tried a hybrid approach... Method 3: Keep the update list. But loop over all the channels continuously, and within each iteration check if the update list has updated. If it has, go with the number pushed onto it. If it hasn't, check the channel we've currently iterated to. void method_three() { std::vector<Data*> channel_cursors; for(ChannelList::iterator i = channel_list.begin(); i != channel_list.end(); ++i) { Data* current_item = static_cast<Data*>(i->get(segment)->tail_.get(segment)); channel_cursors.push_back(current_item); } UpdateID* update_cursor = static_cast<UpdateID*>(update_channel.tail_.get(segment)); while(true) { for(std::size_t i = 0; i < channel_list.size(); ++i) { std::size_t idx = i; ACQUIRE_MEMORY_BARRIER; if(update_cursor->state_ != NOT_FILLED_YET) { //std::cerr << "Found via update" << std::endl; i--; idx = update_cursor->list_id_; update_cursor = static_cast<UpdateID*>(update_cursor->next_.get(segment)); } Data* current_item = channel_cursors[idx]; ACQUIRE_MEMORY_BARRIER; if(current_item->state_ == NOT_FILLED_YET) { continue; } found_an_update = true; log_latency(current_item->tv_sec_, current_item->tv_usec_); channel_cursors[idx] = static_cast<Data*>(current_item->next_.get(segment)); } } } The latency of this method was as good as Method 1, but scaled to large numbers of channels. The problem is, I have no clue why. Just to throw a wrench in things: if I uncomment the 'found via update' part, it prints between EVERY LATENCY LOG MESSAGE. Which means things are only ever found on the update list! So I don't understand how this method can be faster than method 2. The full, compilable code (requires GCC and boost-1.41) that generates random strings as test data is at: http://pastebin.com/e3HuL0nr

    Read the article

  • Why doesn't Python have a "flatten" function for lists?

    - by Hubro
    Erlang and Ruby both come with functions for flattening arrays. It seems like such a simple and useful tool to add to a language. One could do this: >>> mess = [[1, [2]], 3, [[[4, 5]], 6]] >>> mess.flatten() [1, 2, 3, 4, 5, 6] Or even: >>> import itertools >>> mess = [[1, [2]], 3, [[[4, 5]], 6]] >>> list(itertools.flatten(mess)) [1, 2, 3, 4, 5, 6] Instead, in Python, one has to go through the trouble of writing a function for flattening arrays from scratch. This seems silly to me, flattening arrays is such a common thing to do. It's like having to write a custom function for concatenating two arrays. I have Googled this fruitlessly, so I'm asking here; is there a particular reason why a mature language like Python 3, which comes with a hundred thousand various batteries included, doesn't provide a simple method of flattening arrays? Has the idea of including such a function been discussed and rejected at some point?

    Read the article

  • Process arbitrarily large lists without explicit recursion or abstract list functions?

    - by Erica Xu
    This is one of the bonus questions in my assignment. The specific questions is to see the input list as a set and output all subsets of it in a list. We can only use cons, first, rest, empty?, empty, lambda, and cond. And we can only define exactly once. But after a night's thinking I don't see it possible to go through the arbitrarily long list without map or foldr. Is there a way to perform recursion or alternative of recursion with only these functions?

    Read the article

  • From the Tips Box: Quick File Renaming in Windows 7, Fast Access to Web Sites on Android, and GPS-based Todo Lists

    - by Jason Fitzpatrick
    Once a week we round up some reader tips and share them with the greater How-To Geek audience. This week we’re looking at speedy file renaming in Windows 7, fast access to bookmarks in Android, and a neat GPS-based todo list. How to Stress Test the Hard Drives in Your PC or Server How To Customize Your Android Lock Screen with WidgetLocker The Best Free Portable Apps for Your Flash Drive Toolkit

    Read the article

< Previous Page | 20 21 22 23 24 25 26 27 28 29 30 31  | Next Page >