unique

Python sum of non duplicate int

限于喜欢 提交于 2019-12-11 05:07:22
问题 I am given 3 int, a, b, c. I would like to find the sum of all three int provided that they are unique. If a, b, or c has the same values as any of the other values, then they don't count towards the sum. Example 1: a = 3, b = 3, c =3 sum = 0 Example 2 a = 1, b = 3, c =3 sum = 1 This is what I have done. Is there a more pythonic way of doing this without so many if else statements? def lone_sum(a, b, c): if a != b and b != c and a != c: return a + b + c elif a == b == c: return 0 elif a == b:

Generate unique code from primary key

二次信任 提交于 2019-12-11 04:57:28
问题 I have a table of orders and I want to give users a unique code for an order whilst hiding the incrementing identity integer primary key because I don't want to give away how many orders have been made. One easy way of making sure the codes are unique is to use the primary key to determine the code. So how can I transform an integer into a friendly, say, eight alpha numeric code such that every code is unique? 回答1: Assuming the total number of orders being created isn't going to get anywhere

Select a subgroup of records by one distinct column

半世苍凉 提交于 2019-12-11 04:32:22
问题 Sorry if this has been answered before, but all the related questions didn't quite seem to match my purpose. I have a table that looks like the following: ID POSS_PHONE CELL_FLAG ======================= 1 111-111-1111 0 2 222-222-2222 0 2 333-333-3333 1 3 444-444-4444 1 I want to select only distinct ID values for an insert, but I don't care which specific ID gets pulled out of the duplicates. For Example(a valid SELECT would be): 1 111-111-1111 0 2 222-222-2222 0 3 444-444-4444 1 Before I

Select N random records in SQL Server without repetition

对着背影说爱祢 提交于 2019-12-11 04:32:06
问题 How do I select N random records from a table at a time without repetition of records previously returned by the same operation? An obvious solution is: SELECT TOP 5 * FROM MyTable WHERE Id NOT IN (SELECT Id FROM PreviouslyReturned) ORDER BY newid() But wouldn't that be really inefficient as MyTable starts to grow? I have a long list of records and I require five records at a time for a turn-based game without repeating any of the records already pulled for the given game. Since I know

How to compare records within the same table and find missing records

蹲街弑〆低调 提交于 2019-12-11 04:01:25
问题 Here is a simplified version of my table Name Vlan Switch 1 1 Switch 1 2 Switch 1 3 Switch 2 1 Switch 2 2 I want to compare all vlans belonging to switch 1 with all vlans belonging to switch 2 and print out the missing ones in one of the switches using SQL query. Is it possible to do so? Note all data resides inside the same table. On the example data provided above, the query should return Row 3 Switch 1, 3 Here is the query I tried earlier (my requirement has few more conditions than the

XML Schema add unique id for several child elements

家住魔仙堡 提交于 2019-12-11 03:45:41
问题 I have an XML file that stores movies and their actors. There are 2 movie elements (+ their movieID attribute) that contain 2 actorID each. Each actorID also contains known_for/movies/movie that also has a movieID. I have managed to make "the main" movieID to be unique and actorID to be unique within that movieID. However, I also want to make movieID inside known_for/movies/movie element to be unique within their corresponding actorID. I am a bit confused on where do I need to define unique

Array of literal Objects without duplicates in ES6 using Set

强颜欢笑 提交于 2019-12-11 03:36:24
问题 The code to get an array without repeated items has become elegant since ES6 : [...new Set(array)]; That's it! However, this is only removing duplicates if the array has elements with a primitive data type (string, boolean, number, ...). What about a Set of object literals? How to make that work without getting duplicates, using a syntax close to the syntax used above ? var array=["aaa","bbb","aaa","cc","aaa","bbb"]; var out=[...new Set(array)]; console.log(out) //----Literal Object array=[{n

Efficiently find unique elements in 2-dim array T[][] in C#

安稳与你 提交于 2019-12-11 03:24:54
问题 One solution to extract unique values would be to apply Array[i].Distinct() to each row and then form the list of all the unique elements from each row. Then we can repeat for this list List.Distinct() . But is there more efficient way how to create T[] UniqueValues out of T[][] Data ? Thanks 回答1: var distinct = array.SelectMany(a => a).Distinct().ToArray(); This simply flattens the nested arrays into a sequence and calls Distinct to find the distinct elements. The call to ToArray may be

Postgresql SELECT random with unique value

情到浓时终转凉″ 提交于 2019-12-11 03:23:46
问题 I am not able to make one clean SELECT I have postgresql table with fields id , providerid, deal_name I want to make random select with unique providerid SELECT * FROM deals ORDER BY random() LIMIT 10 How I can set this to return 10 results with unique providerid's ? 回答1: Can your question be rephrased as: "For each of ten randomly selected providers, find one randomly selected deal offered by that provider" ? If so, that pretty much tells you what to do. You need two layers, one pass to

Is an OAuth 2.0 token forever unique to the provider?

别来无恙 提交于 2019-12-11 02:26:39
问题 When an OAuth 2.0 provider issues a token, is that token value forever unique to the provider? Or is it possible that sometime in the future, presumably after the token expires, another token, potentially for a different user, could be issued with the same value? In searching I found much information about tokens expiring, but no details about if that token value could potentially be re-used in the future. 回答1: There's nothing in the core OAuth 2 spec that guarantees this. It is