Search Results

Search found 31694 results on 1268 pages for 'list'.

Page 11/1268 | < Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >

  • F# Active Pattern List.filter or equivalent

    - by akaphenom
    I have a records of types type tradeLeg = { id : int ; tradeId : int ; legActivity : LegActivityType ; actedOn : DateTime ; estimates : legComponents ; entryType : ShareOrDollarBased ; confirmedPrice: DollarsPerShare option; actuals : legComponents option ; type trade = { id : int ; securityId : int ; ricCode : string ; tradeActivity : TradeType ; enteredOn : DateTime ; closedOn : DateTime ; tradeLegs : tradeLeg list ; } Obviously the tradeLegs are a type off of a trade. A leg may be settled or unsettled (or unsettled but price confirmed) - thus I have defined the active pattern: let (|LegIsSettled|LegIsConfirmed|LegIsUnsettled|) (l: tradeLeg) = if Helper.exists l.actuals then LegIsSettled elif Helper.exists l.confirmedPrice then LegIsConfirmed else LegIsUnsettled and then to determine if a trade is settled (based on all legs matching LegIsSettled pattern: let (|TradeIsSettled|TradeIsUnsettled|) (t: trade) = if List.exists ( fun l -> match l with | LegIsSettled -> false | _ -> true) t.tradeLegs then TradeIsSettled else TradeIsUnsettled I can see some advantages of this use of active patterns, however i would think there is a more efficient way to see if any item of a list either matches (or doesn't) an actie pattern without having to write a lambda expression specifically for it, and using List.exist. Question is two fold: is there a more concise way to express this? is there a way to abstract the functionality / expression (fun l - match l with | LegIsSettled - false | _ - true) Such that let itemMatchesPattern pattern item = match item with | pattern -> true | _ -> false such I could write (as I am reusing this design-pattern): let curriedItemMatchesPattern = itemMatchesPattern LegIsSettled if List.exists curriedItemMatchesPattern t.tradeLegs then TradeIsSettled else TradeIsUnsettled Thoughts?

    Read the article

  • C# remove redundant paths from a list

    - by andrew
    Say I have this list List<string> sampleList = new List<string> { "C:\\Folder1", "D:\\Folder2", "C:\\Folder1\\Folder3", "C:\\Folder111\\Folder4" }; I'd like to remove the paths that are contained in other folders, for example we have C:\Folder1 and C:\Folder1\Folder3 the second entry should go away because C:\Folder1 contains C:\Folder1\Folder3 is there something that does that in the .net framework or do i have to write the algo myself?

    Read the article

  • parsing list in python

    - by lakshmipathi
    I have list in python which has following entries name-1 name-2 name-3 name-4 name-1 name-2 name-3 name-4 name-1 name-2 name-3 name-4 I would like remove name-1 from list except its first appearance -- resultant list should look like name-1 name-2 name-3 name-4 name-2 name-3 name-4 name-2 name-3 name-4 How to achieve this ?

    Read the article

  • Racket: change dotted pair to list

    - by user2963128
    I have a program that recursively calls a hashtable and prints out data from it. Unfortunately my hashtable seems to be saving data as dotted pairs so when I call the hashtable I get an error saying that there is no data for it because its tryign to search the hashtable for a dotted pair instead of a list. Is there an easy way to make the dotted pair into a regular list? IE im getting '("was" . "beginning") instead of '("was" "beginning") Is there a way to change this without re-writing how my hashtable store stuff? im using the let function to set a variable to this and then calling another function based on this variable (let ((data ( list-ref(hash-ref Ngram-table key) (random (length (hash-ref Ngram-table key)))))) is there a way to make the value stored in data just a list like this '("var1" "var2") instead of a dotted pair? edit: im getting dotted pairs because im using let to set data to the part of the hashtable's key and one of the elements in that hash.

    Read the article

  • List.Sort in C#: comparer being called with null object

    - by cbp
    I am getting strange behaviour using the built-in C# List.Sort function with a custom comparer. For some reason it sometimes calls the comparer class's Compare method with a null object as one of the parameters. But if I check the list with the debugger there are no null objects in the collection. My comparer class looks like this: public class DelegateToComparer<T> : IComparer<T> { private readonly Func<T,T,int> _comparer; public int Compare(T x, T y) { return _comparer(x, y); } public DelegateToComparer(Func<T, T, int> comparer) { _comparer = comparer; } } This allows a delegate to be passed to the List.Sort method, like this: mylist.Sort(new DelegateToComparer<MyClass>( (x, y) => { return x.SomeProp.CompareTo(y.SomeProp); }); So the above delegate will throw a null reference exception for the x parameter, even though no elements of mylist are null. UPDATE: Yes I am absolutely sure that it is parameter x throwing the null reference exception! UPDATE: Instead of using the framework's List.Sort method, I tried a custom sort method (i.e. new BubbleSort().Sort(mylist)) and the problem went away. As I suspected, the List.Sort method passes null to the comparer for some reason.

    Read the article

  • Sharepoint List Filter by Profile Property

    - by Lina Al Dana
    How would you filter a list in Sharepoint (WSS 3.0) by a current user's profile property. For example, I have a list with a Department column and I want to filter the list based on the current user's department (which would be a user profile's property). Any idea's on how to do this?

    Read the article

  • Using jQuery to Dynamically Insert Into List Alphabetically

    - by Dex
    I have two ordered lists next to each other. When I take a node out of one list I want to insert it alphabetically into the other list. The catch is that I want to take just the one element out and place it back in the other list without refreshing the entire list. The strange thing is that when I insert into the list on the right, it works fine, but when I insert back into the list on the left, the order never comes out right. I have also tried reading everything into an array and sorting it there just in case the children() method isn't returning things in the order they are displayed, but I still get the same results. Here is my jQuery: function moveNode(node, to_list, order_by){ rightful_index = 1; $(to_list) .children() .each(function(){ var ordering_field = (order_by == "A") ? "ingredient_display" : "local_counter"; var compA = $(node).attr(ordering_field).toUpperCase(); var compB = $(this).attr(ordering_field).toUpperCase(); var C = ((compA > compB) ? 1 : 0); if( C == 1 ){ rightful_index++; } }); if(rightful_index > $(to_list).children().length){ $(node).fadeOut("fast", function(){ $(to_list).append($(node)); $(node).fadeIn("fast"); }); }else{ $(node).fadeOut("fast", function(){ $(to_list + " li:nth-child(" + rightful_index + ")").before($(node)); $(node).fadeIn("fast"); }); } } Here is what my html looks like: <ol> <li ingredient_display="Enriched Pasta" ingredient_id="101635" local_counter="1"> <span class="rank">1</span> <span class="rounded-corners"> <span class="plus_sign">&nbsp;&nbsp;+&nbsp;&nbsp;</span> <div class="ingredient">Enriched Pasta</div> <span class="minus_sign">&nbsp;&nbsp;-&nbsp;&nbsp;</span> </span> </li> </ol>

    Read the article

  • Passing empty list as parameter to JPA query throws error

    - by Tuukka Mustonen
    If I pass an empty list into a JPA query, I get an error. For example: List<Municipality> municipalities = myDao.findAll(); // returns empty list em.createQuery("SELECT p FROM Profile p JOIN p.municipality m WHERE m IN (:municipalities)") .setParameter("municipalities", municipalities) .getResultList(); Because the list is empty, Hibernate generates this in SQL as "IN ()", which gives me error with Hypersonic database. There is a ticket for this in Hibernate issue tracking but there are not many comments/activity there. I don't know about support in other ORM products or in JPA spec either. I don't like the idea of having to manually check for null objects and empty lists every time. Is there some commonly known approach/extension to this? How do you handle these situations?

    Read the article

  • Insert a list of objects using MyBatis 3

    - by T Soares
    I've tried to insert a list in a database but I've got some the error: org.springframework.jdbc.BadSqlGrammarException: SqlSession operation; bad SQL grammar []; nested exception is java.sql.SQLException: ORA-00913: too many values (...). The code that I've used: <insert id="insertListMyObject" parameterType="java.util.List" > INSERT INTO my_table (ID_ITEM, ATT1, ATT2) VALUES <foreach collection="list" item="item" index="index" open="(" close=")" separator=","> #{item.idItem, jdbcType=BIGINT}, #{item.att1, jdbcType=INTEGER}, #{item.att2, jdbcType=STRING} </foreach> </insert> My dao cals the method: SqlSessionTemplate().insert(MAPPER+".insertListMyObject", parameterList); Where the parameterList is: List<MyObjects>. Does someone have a clue about what's this error? Or if does exists a better way to do multiples inserts operation. Many thanks!

    Read the article

  • Converting a list of an Structure into datatable

    - by strakastroukas
    I saw a lot of examples regarding conversion of a list to data-table. I would like to convert a list of structure into a data-table. How can i do that? My structure is like ... Structure MainStruct Dim Ans1 As String Dim Ans2 As String Dim Ans3 As String Dim Skipped As Boolean End Structure and... Dim St As New MainStruct Dim Build As New List(Of MainStruct) I would like to convert the Build to a datatable

    Read the article

  • A linked list with multiple heads in Java

    - by Emile
    Hi, I have a list in which I'd like to keep several head pointers. I've tried to create multiple ListIterators on the same list but this forbid me to add new elements in my list... (see Concurrent Modification exception). I could create my own class but I'd rather use a built-in implementation ;) To be more specific, here is an inefficient implementation of two basic operations and the one wich doesn't work : class MyList <E { private int[] _heads; private List<E _l; public MyList ( int nbHeads ) { _heads = new int[nbHeads]; _l = new LinkedList<E(); } public void add ( E e ) { _l.add(e); } public E next ( int head ) { return _l.get(_heads[head++]); // ugly } } class MyList <E { private Vector<ListIterator<E _iters; private List<E _l; public MyList ( int nbHeads ) { _iters = new Vector<ListIterator<E(nbHeads); _l = new LinkedList<E(); for( ListIterator<E iter : _iters ) iter = _l.listIterator(); } public void add ( E e ) { _l.add(e); } public E next ( int head ) { // ConcurrentModificationException because of the add() return _iters.get(head).next(); } } Emile

    Read the article

  • Efficient method to calculate the rank vector of a list in Python

    - by Tamás
    I'm looking for an efficient way to calculate the rank vector of a list in Python, similar to R's rank function. In a simple list with no ties between the elements, element i of the rank vector of a list l should be x if and only if l[i] is the x-th element in the sorted list. This is simple so far, the following code snippet does the trick: def rank_simple(vector): return [rank for rank in sorted(range(n), key=vector.__getitem__)] Things get complicated, however, if the original list has ties (i.e. multiple elements with the same value). In that case, all the elements having the same value should have the same rank, which is the average of their ranks obtained using the naive method above. So, for instance, if I have [1, 2, 3, 3, 3, 4, 5], the naive ranking gives me [0, 1, 2, 3, 4, 5, 6], but what I would like to have is [0, 1, 3, 3, 3, 5, 6]. Which one would be the most efficient way to do this in Python? Footnote: I don't know if NumPy already has a method to achieve this or not; if it does, please let me know, but I would be interested in a pure Python solution anyway as I'm developing a tool which should work without NumPy as well.

    Read the article

  • Python: Remove items from a list while iterating in Python

    - by xApple
    My problem is simple: I have a long list of elements that I want to iterate through and check every element against a condition. Depending on the outcome of the condition I would like to delete the current element of the list, and continue iterating over it as usual. I have read a few other threads on this matter. Two solutions seam to be proposed. Either make a dictionary out of the list (which implies making a copy of all the data that is already filling all the RAM in my case). Either walk the list in reverse (which breaks the concept of the alogrithm I want to implement). Is there any better or more elegant way than this to do it ? def walk_list(list_of_g): g_index = 0 while g_index < len(list_of_g): g_current = list_of_g[g_index] if subtle_condition(g_current): list_of_g.pop(g_index) else: g_index = g_index + 1

    Read the article

  • Generic List created at runtime

    - by Perry
    Hi... i neeed something like this in C#.. have list in class but decide what will be in list during runtime class A { List data; Type typeOfDataInList; } public void FillData(DataTyp[] data) where DataTyp : struct { A a = new A(); A.vListuBudouDataTypu = typeof(DataTyp); A.data = new List(); A.AddRange(data); } Is this possible to do something like this ?

    Read the article

  • Reverse a singly linked list

    - by Madhan
    I would be wondered if there exists some logic to reverse the linked list using only two pointers. The following is used to reverse the single linked list using three pointers namely p, q, r: struct node { int data; struct node *link; }; void reverse() { struct node *p = first, *q = NULL, *r; while (p != NULL) { r = q; q = p; p = p->link; q->link = r; } q = first; } Is there any other alternate to reverse the linked list? what would be the best logic to reverse a singly linked list, in terms of time complexity?

    Read the article

  • Multiple objects in list, C#

    - by anon
    I'm looking for something similar to List<T>, that would allow me to have multiple T. For example: List<TabItem, DataGrid, int, string, ...> = new List<TabItem, DataGrid, int, string, ...>().

    Read the article

  • Algorithm - combine multiple lists, resulting in unique list and retaining order

    - by hitch
    I want to combine multiple lists of items into a single list, retaining the overall order requirements. i.e.: 1: A C E 2: D E 3: B A D result: B A C D E above, starting with list 1, we have ACE, we then know that D must come before E, and from list 3, we know that B must come before A, and D must come after B and A. If there are conflicting orderings, the first ordering should be used. i.e. 1: A C E 2: B D E 3: F D result: A C B D E F 3 conflicts with 2, therefore requirements for 2 will be used. If ordering requirements mean an item must come before or after another, it doesn't matter if it comes immediately before or after, or at the start or end of the list, as long as overall ordering is maintained. This is being developed using VB.Net, so a LINQy solution (or any .Net solution) would be nice - otherwise pointers for an approach would be good.

    Read the article

  • Get the first and second objects from a list using LINQ

    - by Vahid
    I have a list of Person objects. How can I get the first and second Person objects that meet a certain criteria from List<Person> People using LINQ? Let's say here is the list I've got. How can I get the first and second persons that are over 18 that is James and Jodie. public class Person { public string Name; public int age; } var People = new List<Person> { new Person {Name = "Jack", Age = 15}, new Person {Name = "James" , Age = 19}, new Person {Name = "John" , Age = 14}, new Person {Name = "Jodie" , Age = 21}, new Person {Name = "Jessie" , Age = 19} }

    Read the article

  • Deleting a node from linked list in C

    - by LuckySlevin
    My problem is deleting a node from linked list. I have two structs : typedef struct inner_list { int count; char word[100]; inner_list*next; } inner_list; typedef struct outer_list { char word [100]; inner_list * head; int count; outer_list * next; } outer_list; My problem is in deleting a node from outer_list linked list. For example when user entered aaa to delete, delete function should find the node with outer_list->word = aaa and delete this node and reconnect the list again. I tried the below code to do this. but After finding and deleting I'm losing the list. I don't know what's wrong. Please notice that outer_list have also a linked list of inner_list inside. void delnode(outer_list *head,char num[100]) { outer_list *temp, *m; temp=head; while(temp!=NULL) { if(strcmp(temp->word==num)==0) { if(temp==head) { head=temp->next; free(temp); return; } else { m->next=temp->next; free(temp); return; } }else { m=temp; temp= temp->next; } } printf(" ELEMENT %s NOT FOUND ", num); } What are your ideas about this?

    Read the article

  • Counting entries in a list of dictionaries: for loop vs. list comprehension with map(itemgetter)

    - by Dennis Williamson
    In a Python program I'm writing I've compared using a for loop and increment variables versus list comprehension with map(itemgetter) and len() when counting entries in dictionaries which are in a list. It takes the same time using a each method. Am I doing something wrong or is there a better approach? Here is a greatly simplified and shortened data structure: list = [ {'key1': True, 'dontcare': False, 'ignoreme': False, 'key2': True, 'filenotfound': 'biscuits and gravy'}, {'key1': False, 'dontcare': False, 'ignoreme': False, 'key2': True, 'filenotfound': 'peaches and cream'}, {'key1': True, 'dontcare': False, 'ignoreme': False, 'key2': False, 'filenotfound': 'Abbott and Costello'}, {'key1': False, 'dontcare': False, 'ignoreme': True, 'key2': False, 'filenotfound': 'over and under'}, {'key1': True, 'dontcare': True, 'ignoreme': False, 'key2': True, 'filenotfound': 'Scotch and... well... neat, thanks'} ] Here is the for loop version: #!/usr/bin/env python # Python 2.6 # count the entries where key1 is True # keep a separate count for the subset that also have key2 True key1 = key2 = 0 for dictionary in list: if dictionary["key1"]: key1 += 1 if dictionary["key2"]: key2 += 1 print "Counts: key1: " + str(key1) + ", subset key2: " + str(key2) Output for the data above: Counts: key1: 3, subset key2: 2 Here is the other, perhaps more Pythonic, version: #!/usr/bin/env python # Python 2.6 # count the entries where key1 is True # keep a separate count for the subset that also have key2 True from operator import itemgetter KEY1 = 0 KEY2 = 1 getentries = itemgetter("key1", "key2") entries = map(getentries, list) key1 = len([x for x in entries if x[KEY1]]) key2 = len([x for x in entries if x[KEY1] and x[KEY2]]) print "Counts: key1: " + str(key1) + ", subset key2: " + str(key2) Output for the data above (same as before): Counts: key1: 3, subset key2: 2 I'm a tiny bit surprised these take the same amount of time. I wonder if there's something faster. I'm sure I'm overlooking something simple. One alternative I've considered is loading the data into a database and doing SQL queries, but the data doesn't need to persist and I'd have to profile the overhead of the data transfer, etc., and a database may not always be available. I have no control over the original form of the data. The code above is not going for style points.

    Read the article

< Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >