matching

How to efficiently find the indices of matching elements in two lists

安稳与你 提交于 2019-12-20 18:25:44
问题 I am working on two large data sets, and my question is as follows. Suppose I have two lists: list1 = [A,B,C,D] list2 = [B,D,A,G] How can I efficiently find the matching index, using Python, other than O(n 2 ) searching? The result should look like: matching_index(list1,list2) -> [(0,2),(1,0),(3,1)] 回答1: Without duplicates If your objects are hashable and your lists have no duplicates, you can create an inverted index of the first list and then traverse the second list. This traverses each

Worker Scheduling Algorithm

浪子不回头ぞ 提交于 2019-12-20 10:38:03
问题 The Problem Here's the essence of the problem I want to solve. We have workers taking care of children in a nursery for set times during the weekend. There's 16 different slots to fill in one weekend. So for a 4-week month there's 64 slots to fill. We have at max 30 nursery workers (though we need much more. anybody like kids?). EDIT: Each time slot is discrete - they don't overlap. Currently there's a person who comes up with the nursery schedule each month. It's a complex and time consuming

Running queries against a list of lists in Scheme

烈酒焚心 提交于 2019-12-20 07:38:02
问题 I'm stuck in the middle of my project. I have a list of lists like: '((a for apple) (b is book) (c in cat) (ronn live in NY)) Now I want to make a query in the form of a list and have it display the correct entry in my list of lists. For example, if I input '(a for what) or '(what in cat) it will display (a for apple) or (c in cat) . If I input '(ronn live in where) it will show (ronn live in NY) . Can anyone help me solve this problem? 回答1: How about running a filter routine across the list,

C#: finding instances of a string within a string

£可爱£侵袭症+ 提交于 2019-12-20 06:35:27
问题 Suppose I had the string "1 AND 2 AND 3 OR 4", and want to create an array of strings that contains all substrings "AND" or "OR", in order, found within the string. So the above string would return a string array of {"AND", "AND", "OR"}. What would be a smart way of writing that? EDIT: Using C# 2.0+, string rule = "1 AND 2 AND 3 OR 4"; string pattern = "(AND|OR)"; string[] conditions = Regex.Split(rule, pattern); gives me {"1", "AND", "2", "AND", "3", "OR", "4"}, which isn't quite what I'm

Python: How to return list of booleans to see if elements of one list in another list

这一生的挚爱 提交于 2019-12-20 05:43:08
问题 I have two lists: A = [1,2,3,4,5,6,7,8] B = [2,3,4] and want to get a boolean list of length(A) where the element at each index indicates whether the element at the same index in A is in anywhere in the list B. The return value would be: [False, True, True, True, False, False, False, False] It would be easy to write a function, but want to know if there is a paradigmatic way of doing it in Python. In R, the counterpart would be which(A %in% b) 回答1: use a list comprehension: In [164]: A = [1,2

Good algorithm for matching names?

好久不见. 提交于 2019-12-19 10:07:46
问题 I'm developing an app for mobile phones that syncs the contacts with the facebook account. So basically I have a list of my contacts names and a list of my facebook friends and I want to get the best possible matching between the two lists. Of course i can write something basic myself, but maybe there is a known algorithm out there that gets really good results. What do you think? 回答1: Maybe you can try Levenshtein distance 回答2: Soundex 回答3: You might find the results the MITRE name matching

Emacs matching tags highlighting

可紊 提交于 2019-12-19 05:46:49
问题 When Paren Match Highlighting (in the Options menu) is enabled, it nicely highlights matched parentheses. Is there something like this but for XML tags? For example, if I had: <para> lksjdflksdjfksdjf </para> it would highlight both tags if my point was anywhere inside one of the tags (even including the less-than and greater-than signs). Thanks for help! 回答1: Mike Spindel has written a minor mode, hl-tags-mode, which provides this feature. 来源: https://stackoverflow.com/questions/7784334

R - Assign column value based on closest match in second data frame

戏子无情 提交于 2019-12-19 03:07:14
问题 I have two data frames, logger and df (times are numeric): logger <- data.frame( time = c(1280248354:1280248413), temp = runif(60,min=18,max=24.5) ) df <- data.frame( obs = c(1:10), time = runif(10,min=1280248354,max=1280248413), temp = NA ) I would like to search logger$time for the closest match to each row in df$time, and assign the associated logger$temp to df$temp. So far, I have been successful using the following loop: for (i in 1:length(df$time)){ closestto<-which.min(abs((logger$time

matching against words with accent marks, umlauts, etc. mysql/php

◇◆丶佛笑我妖孽 提交于 2019-12-18 07:25:20
问题 I've got a website for which I just wrote a great search function. I just realized that I have some words in my db with accent marks. So when somebody types in the word to search for, without the accent mark of course, they don't find what they are looking for. most search functions have solved this problem by now; how do they do it? There must be some clever trick to it. Most of my queries use mysql's MATCH feature but one of them uses LIKE. 回答1: You need to set a particular collation on

matching against words with accent marks, umlauts, etc. mysql/php

爷,独闯天下 提交于 2019-12-18 07:25:12
问题 I've got a website for which I just wrote a great search function. I just realized that I have some words in my db with accent marks. So when somebody types in the word to search for, without the accent mark of course, they don't find what they are looking for. most search functions have solved this problem by now; how do they do it? There must be some clever trick to it. Most of my queries use mysql's MATCH feature but one of them uses LIKE. 回答1: You need to set a particular collation on