Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a list of lists into single list F#

Tags:

f#

I have a list of lists

LL = [[1;2;3];[4;5;6];[7;8;9]]

And I would like it to look like this

LSimple= [1;2;3;4;5;6;7;8;9]

That's as simple as I can ask it, but maybe rewording helps. How can I parse this lists of lists and create a simple list from it?

like image 646
user3507072 Avatar asked Feb 25 '15 06:02

user3507072


People also ask

How do I make a list in a single list?

There are a number of ways to flatten a list of lists in python. You can use a list comprehension, the itertools library, or simply loop through the list of lists adding each item to a separate list, etc. Let's see them in action through examples followed by a runtime assessment of each.

How do I turn a list into a single list in Python?

Flatten List of Lists Using itertools (chain()) This approach is ideal for transforming a 2-D list into a single flat list as it treats consecutive sequences as a single sequence by iterating through the iterable passed as the argument in a sequential manner.

How do you combine lists within a list Python?

📢 TLDR: Use + In almost all simple situations, using list1 + list2 is the way you want to concatenate lists. The edge cases below are better in some situations, but + is generally the best choice. All options covered work in Python 2.3, Python 2.7, and all versions of Python 31.


1 Answers

List.concat LL 

Will do what you want. The X.concat family of functions concatenate any sequence of the collection X to a single X where X may be a List, Array, Seq or even a String with a given separator.

like image 170
Gus Avatar answered Oct 22 '22 12:10

Gus