intersection

Python - Intersectiing strings

耗尽温柔 提交于 2019-12-01 17:37:19
Trying to write a for function that takes two strings and returns the characters that intersect in the order that they appear in the first string. Here's what I tried: def strIntersection(str1, str2): for i in str1: str3 = '' str3 = str3.join(i for i in str1 if i in str2 not in str3) return str3 str1 = 'asdfasdfasfd' str2 = 'qazwsxedc' strIntersection(str1,str2) => 'asdasdasd' however I only want the the intersection characters to appear once and in order of the first string ie. 'asd' Can anyone help? I've found some similar problems on other forums but the solutions all seem to involve lists

Filter MongoDb collection if field array and argument array intersect

拥有回忆 提交于 2019-12-01 15:40:13
问题 I'm creating a Meteor learning project. There is a collection in it, its documents have a property named keywords which is an array of strings. I have a second array of strings. I want to filter the collection that way, that it returned only those documents which keywords array intersect with that second array, i.e. both arrays have one or several same elements. Is it possible? 回答1: Yes, a query would be: var searchKeywords = ['a','b','c','d'] MyCollection = new Mongo.Collection('mycollection

Find all intersecting data, not just the unique values

被刻印的时光 ゝ 提交于 2019-12-01 15:17:56
I thought that I understood Intersect , but it turns out I was wrong. List<int> list1 = new List<int>() { 1, 2, 3, 2, 3}; List<int> list2 = new List<int>() { 2, 3, 4, 3, 4}; list1.Intersect(list2) => 2,3 //But what I want is: // => 2,3,2,3,2,3,3 I can figure a way like: var intersected = list1.Intersect(list2); var list3 = new List<int>(); list3.AddRange(list1.Where(I => intersected.Contains(I))); list3.AddRange(list2.Where(I => intersected.Contains(I))); Is there a easier way in LINQ to achieve this? I do need to state that I do not care in which order the results are given. 2,2,2,3,3,3,3

Something like a tag cache and querying it for suggesting them using Redis

无人久伴 提交于 2019-12-01 14:49:39
It would be like StackOverflow: when you ask a question you need to provide some tags. Currently I'm querying the relational database store, but I believe that Redis should make sense in order to cache tag suggestions. For example, it would be a set like this: sadd tags:suggestions "c#" ".net" "redis" Now some user is asking a question and he/she may write "ne" so there's some tag in the Redis cache that may match the whole partial tag name: .net . I can't figure out how I would intersect such tags:suggestions Redis set in order to get ".net". Or should I use a string instead of a set? Thank

Find all intersecting data, not just the unique values

无人久伴 提交于 2019-12-01 14:16:52
问题 I thought that I understood Intersect , but it turns out I was wrong. List<int> list1 = new List<int>() { 1, 2, 3, 2, 3}; List<int> list2 = new List<int>() { 2, 3, 4, 3, 4}; list1.Intersect(list2) => 2,3 //But what I want is: // => 2,3,2,3,2,3,3 I can figure a way like: var intersected = list1.Intersect(list2); var list3 = new List<int>(); list3.AddRange(list1.Where(I => intersected.Contains(I))); list3.AddRange(list2.Where(I => intersected.Contains(I))); Is there a easier way in LINQ to

Great Circle & Rhumb line intersection [closed]

扶醉桌前 提交于 2019-12-01 14:04:24
I have a Latitude, Longitude, and a direction of travel in degrees true north. I would like to calculate if I will intersect a line defined by two more Lat/Lon points. I figure the two points defining the line would create my great circle and my location and azimuth would define my Rhumb line. I am only interested in intersections that will occur with a few hundred kilometers so I do not need every possible solution. I have no idea where to begin. The simple answer is yes -- if you start from any lat/lon and continue traveling along some great circle, you will eventually cross any and all

Something like a tag cache and querying it for suggesting them using Redis

人盡茶涼 提交于 2019-12-01 13:34:06
问题 It would be like StackOverflow: when you ask a question you need to provide some tags. Currently I'm querying the relational database store, but I believe that Redis should make sense in order to cache tag suggestions. For example, it would be a set like this: sadd tags:suggestions "c#" ".net" "redis" Now some user is asking a question and he/she may write "ne" so there's some tag in the Redis cache that may match the whole partial tag name: .net . I can't figure out how I would intersect

Great Circle & Rhumb line intersection [closed]

瘦欲@ 提交于 2019-12-01 12:50:10
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I have a Latitude, Longitude, and a direction of travel in degrees true north. I would like to calculate if I will intersect a line defined by two more Lat/Lon points. I figure the two points defining the line would create my great circle and my location and azimuth would define my Rhumb line. I am only

Why intersection of Thrust Library is returning unexpected result?

☆樱花仙子☆ 提交于 2019-12-01 12:27:46
I'm using the library Thrust to get intersection set of a two larger sets of integers. In test with 2 small inputs i got correct results, but when i use two sets with 10^8 and 65535*1024 elements i got a empty set. Who's can explain this problem? Changing the two first variables to smaller values the thrust returns a expected intersection set. My code is following. #include <thrust/set_operations.h> #include <thrust/device_vector.h> #include <thrust/device_ptr.h> #include <iostream> #include <stdio.h> int main() { int sizeArrayLonger = 100*1000*1000; int sizeArraySmaller = 65535*1024; int

Circle - Line Intersection not working properly?

寵の児 提交于 2019-12-01 12:26:14
I wrote this circle-line intersection detection after http://mathworld.wolfram.com/Circle-LineIntersection.html , but it appears like it or I am missing something. public static bool Intersect (Vector2f CirclePos, float CircleRad, Vector2f Point1, Vector2f Point2) { Vector2f p1 = Vector2f.MemCpy(Point1); Vector2f p2 = Vector2f.MemCpy(Point2); // Normalize points p1.X -= CirclePos.X; p1.Y -= CirclePos.Y; p2.X -= CirclePos.X; p2.Y -= CirclePos.Y; float dx = p2.X - p1.X; float dy = p2.Y - p1.Y; float dr = (float)Math.Sqrt((double)(dx * dx) + (double)(dy * dy)); float D = p1.X * p2.Y * p2.X - p1.Y