How to slice a list from an element n to the end in python?
You can leave one end of the slice open by not specifying the value. test[3:] = [3, 4, 5, 6, 7, 8, 9] test[:3] = [0, 1, 2]
You can leave one end of the slice open by not specifying the value. test[3:] = [3, 4, 5, 6, 7, 8, 9] test[:3] = [0, 1, 2]
The syntax is: a[start:stop] # items start through stop-1 a[start:] # items start through the rest of the array a[:stop] # items from the beginning through stop-1 a[:] # a copy of the whole array There is also the step value, which can be used with any of the above: a[start:stop:step] # start through not … Read more
UUIDs Unless these are generated “in increasing monotonic sequence” they can drastically hurt/fragment indexes. Support for UUID generation varies by system. While usable, I would not use a UUID as my primary clustered index/PK in most cases. If needed I would likely make it a secondary column, perhaps indexed, perhaps not. Some people argue that … Read more
You should use the fact that when you want all permutations of N numbers there are N! possibilities. Therefore each number x from 1..N! encodes such a permutation. Here is a sample that iteratively prints out all permutations of a sting. private static void printPermutationsIterative(String string){ int [] factorials = new int[string.length()+1]; factorials[0] = 1; … Read more
To grant a permission: grant select on schema_name.sequence_name to user_or_role_name; To check which permissions have been granted select * from all_tab_privs where TABLE_NAME = ‘sequence_name’
The forward slash is valid as is and does not need further encoding. The only reserved characters are: > < & % For even more XML entities – http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references
If you can use PL/SQL, try (EDIT: Incorporates Neil’s xlnt suggestion to start at next higher value): SELECT ‘CREATE SEQUENCE transaction_sequence MINVALUE 0 START WITH ‘||MAX(trans_seq_no)+1||’ INCREMENT BY 1 CACHE 20′ INTO v_sql FROM transaction_log; EXECUTE IMMEDIATE v_sql; Another point to consider: By setting the CACHE parameter to 20, you run the risk of losing … Read more
Every number from 1,2,5,6,9,10… is divisible by 4 with remainder 1 or 2. >>> ‘,’.join(str(i) for i in xrange(100) if i % 4 in (1,2)) ‘1,2,5,6,9,10,13,14,…’
RETURNING That’s possible with a single round-trip to the database: INSERT INTO tbl(filename) VALUES (‘my_filename’) RETURNING tbl_id; tbl_id would typically be a serial or IDENTITY (Postgres 10 or later) column. More in the manual. Explicitly fetch value If filename needs to include tbl_id (redundantly), you can still use a single query. Use lastval() or the … Read more
If you only want to flatten it one level you can use concat (apply concat ‘(([1 2]) ([3 4] [5 6]) ([7 8]))) => ([1 2] [3 4] [5 6] [7 8])