# Given a list of lists, how to drop the last item in each (sub)list.

7 messages
Open this post in threaded view
|

## Given a list of lists, how to drop the last item in each (sub)list.

 I have a list like this: [[1,0,0,0,1,1,1,0,0],[1,1,1,0,1,1,1,0,0],[1,0,1,0,0,1,1,0,0],[0,1,0,0,1,1,1,0,0],[0,0,1,0,1,1,1,0,0],[1,0,0,1,1,1,1,0,1]] The 'inner' list is a list of 9 items.  I want to process the list so that a list of lists is returned but the 9th element in each inner list is dropped. So the function type would be [[a]] -> [[a]] So to get started I wrote a function like this: discardparitybyte :: [[Bit]] -> [[Bit]] But then not sure how to transform the inner list. I know I can access the first inner element using take 1 list.  But how do I then access/manipulate this inner list? discardparitybyte (x:xs) = take 9 ??? (take 1 xs) : discardparitybyte ??? -------------- next part -------------- An HTML attachment was scrubbed... URL:
Open this post in threaded view
|

## Given a list of lists, how to drop the last item in each (sub)list.

 Hi Angus, You map the drop function over the list. Something like this will do foo xs = map (take 8) xs On Thu, Jan 2, 2014 at 5:08 PM, Angus Comber wrote: > I have a list like this: > > > [[1,0,0,0,1,1,1,0,0],[1,1,1,0,1,1,1,0,0],[1,0,1,0,0,1,1,0,0],[0,1,0,0,1,1,1,0,0],[0,0,1,0,1,1,1,0,0],[1,0,0,1,1,1,1,0,1]] > > The 'inner' list is a list of 9 items.  I want to process the list so that > a list of lists is returned but the 9th element in each inner list is > dropped. > > So the function type would be [[a]] -> [[a]] > > So to get started I wrote a function like this: > > discardparitybyte :: [[Bit]] -> [[Bit]] > > But then not sure how to transform the inner list. > > I know I can access the first inner element using take 1 list.  But how do > I then access/manipulate this inner list? > > discardparitybyte (x:xs) = take 9 ??? (take 1 xs) : discardparitybyte ??? > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://www.haskell.org/mailman/listinfo/beginners> > -------------- next part -------------- An HTML attachment was scrubbed... URL:
Open this post in threaded view
|

## Given a list of lists, how to drop the last item in each (sub)list.

Open this post in threaded view
|

## Given a list of lists, how to drop the last item in each (sub)list.

Open this post in threaded view
|