Questions tagged [sequences]

A sequence is any type for which there is a bijective relation between the integers `0..n` and the elements of the sequence, and the elements may be accessed in the order `0..n`, where `n` is the number of elements in the sequence.

A sequence is any type for which there is a bijective relation between the integers 0..n and the elements of the sequence, and the elements may be accessed in the order 0..n, where n is the number of elements in the sequence.

A sequence may be infinite, in which case, the relation is with the open range 0....

538 questions
210
votes
21 answers

List all sequences in a Postgres db 8.1 with SQL

I'm converting a db from postgres to mysql. Since i cannot find a tool that does the trick itself, i'm going to convert all postgres sequences to autoincrement ids in mysql with autoincrement value. So, how can i list all sequences in a Postgres DB…
apelliciari
  • 8,241
  • 9
  • 57
  • 92
166
votes
5 answers

In Clojure, when should I use a vector over a list, and the other way around?

I read that Vectors are not seqs, but Lists are. I'm not sure what the rationale is for using one over the other. It seems that vectors are used the most, but is there a reason for that?
Rayne
  • 31,473
  • 17
  • 86
  • 101
124
votes
14 answers

Distributed sequence number generation?

I've generally implemented sequence number generation using database sequences in the past. e.g. Using Postgres SERIAL type http://www.neilconway.org/docs/sequences/ I'm curious though as how to generate sequence numbers for large distributed…
Jonathan Holloway
  • 62,090
  • 32
  • 125
  • 150
93
votes
7 answers

Python: check if an object is a sequence

In python is there an easy way to tell if something is not a sequence? I tried to just do: if x is not sequence but python did not like that
nicotine
  • 2,519
  • 3
  • 19
  • 15
75
votes
1 answer

Kotlin sequence "skip" first N entries

How can I "skip" the first N entries of a kotlin sequence/list? I am looking for the kotlin equivalent of C# LINQ "skip".
GameScripting
  • 16,092
  • 13
  • 59
  • 98
48
votes
3 answers

Sequence contains no elements exception in linq without even using Single

I am not using Single in LINQ below, but I am still getting a 'Sequence contains no elements' exception: allNames = StockCollection.Where((s) => s.Name.IndexOf("A") == 0) .Select((s) => s.Name) …
D J
  • 6,908
  • 13
  • 43
  • 75
44
votes
4 answers

Comprehension for flattening a sequence of sequences?

If I have sequence of sequences (maybe a list of tuples) I can use itertools.chain() to flatten it. But sometimes I feel like I would rather write it as a comprehension. I just can't figure out how to do it. Here's a very construed case: Let's say I…
PEZ
  • 16,821
  • 7
  • 45
  • 66
37
votes
3 answers

How can I remove an item from a sequence in Clojure?

First, I assume each structure-specific sequences would have different ways to remove an item: Vectors could be by index, List could be remove first or last, Set should be passing of the actual item to remove, etc. Second, I assume there are some…
Robert Campbell
  • 6,848
  • 12
  • 63
  • 93
37
votes
6 answers

Programmatic access to On-Line Encyclopedia of Integer Sequences

Is there a way to search and retrieve the results from On-Line Encyclopedia of Integer Sequences (http://oeis.org) programmatically? I have searched their site and the results are always returned in html. They do not seem to provide an API but in…
nabeelmukhtar
  • 1,371
  • 15
  • 24
37
votes
16 answers

How would you implement sequences in Microsoft SQL Server?

Does anyone have a good way of implementing something like a sequence in SQL server? Sometimes you just don't want to use a GUID, besides the fact that they are ugly as heck. Maybe the sequence you want isn't numeric? Besides, inserting a row and…
Nathan Lee
  • 2,231
  • 2
  • 23
  • 26
32
votes
3 answers

Avoiding stack overflow (with F# infinite sequences of sequences)

I have this "learning code" I wrote for the morris seq in f# that suffers from stack overflow that I don't know how to avoid. "morris" returns an infinite sequence of "see and say" sequences (i.e., {{1}, {1,1}, {2,1}, {1,2,1,1}, {1,1,1,2,2,1},…
Tony Lee
  • 5,622
  • 1
  • 28
  • 45
32
votes
4 answers

Is Clojure object-oriented at its heart? (Polymorphism in seqs)

Clojure is a functional lisp, reportedly not at all object-oriented, even though it runs on the JVM, a VM designed for an object oriented language. Clojure provides identical interfaces for iterating over lists and vectors by abstracting them to an…
Steve
  • 1,849
  • 2
  • 19
  • 19
32
votes
5 answers

How can I merge two sequences in clojure?

What is an idiomatic way to merge (or retrieve the union of) two lists (or sequences) in Clojure? (merge l1 l2) doesn't seem to be the solution: a=> (merge '(1 2 3) '(2 3 4)) ((2 3 4) 1 2 3)
user1639206
  • 321
  • 1
  • 3
  • 3
31
votes
3 answers

What does Python treat as reference types?

I assumed sequence types in Python were value types. It turns out they're reference types (Meaning that the value of a variable won't be copied when assigned to a new variable, but referenced). So now I'm wondering, what are the value types in…
Hubro
  • 56,214
  • 69
  • 228
  • 381
25
votes
12 answers

Detecting sequence of at least 3 sequential numbers from a given list

I have a list of numbers e.g. 21,4,7,9,12,22,17,8,2,20,23 I want to be able to pick out sequences of sequential numbers (minimum 3 items in length), so from the example above it would be 7,8,9 and 20,21,22,23. I have played around with a few ugly…
David
  • 8,340
  • 7
  • 49
  • 71
1
2 3
35 36