COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Detele repeated in a list

• Email
• Follow

```Hi everyone!

I have this piece of code, that sould delete all the repeated elements
from a list :

(defun apaga-repetidos (lista)
(let ((p (first lista))
(r (rest lista)))
(if (null lista)
nil
(if (equal p r)
(apaga-repetidos r)
(cons p (apaga-repetidos r))))))

> : (apaga-repetidos '((1 2) (2 2) (3 2) (4 2) (5 2) (6 2) (7 2) (8 2) (8 3)=
(8 4) (7 4) (6 4) (5 4) (4 4) (4 5) (3 5) (3 6) (4 6) (4 5) (4 4) (5 4) ))

But i cant=B4t put this to work. Someone can help me?

Best regards,
Alexandre Almeida
```
 0
Reply thot4ever (8) 6/10/2008 1:31:16 PM

See related articles to this posting

```On 10 jun, 10:31, Alexandre Almeida <thot4e...@gmail.com> wrote:
> Hi everyone!
>
> I have this piece of code, that sould delete all the repeated elements
> from a list :
>
> (defun apaga-repetidos (lista)
> =A0 (let ((p (first lista))
> =A0 =A0 =A0 =A0 (r (rest lista)))
> =A0 =A0 (if (null lista)
> =A0 =A0 =A0 =A0 nil
> =A0 =A0 (if (equal p r)
> =A0 =A0 =A0 =A0 (apaga-repetidos r)
> =A0 =A0 =A0 (cons p (apaga-repetidos r))))))
>

You are comparing an element with a list when you do (equal p r)

Try this:

(defun apaga-repetidos (lista)
(apaga-repetidos-2 lista (make-hash-table :test #'equal)))

(defun apaga-repetidos-2 (lista vistos)
(if (null lista)
nil
(let ((p (first lista))
(r (rest lista)))
(if (gethash p vistos)
(apaga-repetidos-2 r vistos)
(progn
(setf (gethash p vistos) t)
(cons p (apaga-repetidos-2 r vistos)))))))

> > : (apaga-repetidos '((1 2) (2 2) (3 2) (4 2) (5 2) (6 2) (7 2) (8 2) (8 =
3) (8 4) (7 4) (6 4) (5 4) (4 4) (4 5) (3 5) (3 6) (4 6) (4 5) (4 4) (5 4) )=
)
>

Result: ((1 2) (2 2) (3 2) (4 2) (5 2) (6 2) (7 2) (8 2) (8 3) (8 4)
(7 4) (6 4) (5 4)
(4 4) (4 5) (3 5) (3 6) (4 6))

Cheers, Mariano
```
 0
Reply marianomontone (51) 6/10/2008 1:50:26 PM

```On 2008-06-10 09:31:16 -0400, Alexandre Almeida <thot4ever@gmail.com> said:

Assuming that your data will always take the form of a list of two
element lists:

> (defun apaga-repetidos (lista)
>   (let ((p (first lista))
>         (r (rest lista)))
>     (if (null lista)
>         nil
>     (if (equal p r)

^^^^^^^^^^^^^^^^^^^^^
are these really what you want to compare here?
Don't you really want to compare (first p) and (second p)?

>         (apaga-repetidos r)
>       (cons p (apaga-repetidos r))))))

```
 0

```On Jun 10, 3:12 pm, Raffael Cavallaro <raffaelcavallaro@pas-d'espam-
s'il-vous-plait-mac.com> wrote:
> On 2008-06-10 09:31:16 -0400, Alexandre Almeida <thot4e...@gmail.com> said:
>
> Assuming that your data will always take the form of a list of two
> element lists:
>
> > (defun apaga-repetidos (lista)
> >   (let ((p (first lista))
> >         (r (rest lista)))
> >     (if (null lista)
> >         nil
> >     (if (equal p r)
>
> ^^^^^^^^^^^^^^^^^^^^^
> are these really what you want to compare here?

I want to compare a list that is always like this:

'((1 2) (2 2) (3 2) (4 2) (5 2) (6 2) (4 2) (3 2))

And i want to remove the repeated elements

> Don't you really want to compare (first p) and (second p)?
>
> >         (apaga-repetidos r)
> >       (cons p (apaga-repetidos r))))))

```
 0
Reply thot4ever (8) 6/10/2008 2:19:59 PM

```On Jun 10, 2:50 pm, Mariano Montone <marianomont...@gmail.com> wrote:
> On 10 jun, 10:31, Alexandre Almeida <thot4e...@gmail.com> wrote:
>
> > Hi everyone!
>
> > I have this piece of code, that sould delete all the repeated elements
> > from a list :
>
> > (defun apaga-repetidos (lista)
> >   (let ((p (first lista))
> >         (r (rest lista)))
> >     (if (null lista)
> >         nil
> >     (if (equal p r)
> >         (apaga-repetidos r)
> >       (cons p (apaga-repetidos r))))))
>
> You are comparing an element with a list when you do (equal p r)
>
> Try this:
>
> (defun apaga-repetidos (lista)
>    (apaga-repetidos-2 lista (make-hash-table :test #'equal)))
>
> (defun apaga-repetidos-2 (lista vistos)
>    (if (null lista)
>        nil
>        (let ((p (first lista))
>              (r (rest lista)))
>          (if (gethash p vistos)
>              (apaga-repetidos-2 r vistos)
>              (progn
>                (setf (gethash p vistos) t)
>                (cons p (apaga-repetidos-2 r vistos)))))))
>
> > > : (apaga-repetidos '((1 2) (2 2) (3 2) (4 2) (5 2) (6 2) (7 2) (8 2) (8 3) (8 4) (7 4) (6 4) (5 4) (4 4) (4 5) (3 5) (3 6) (4 6) (4 5) (4 4) (5 4) ))
>
> Result: ((1 2) (2 2) (3 2) (4 2) (5 2) (6 2) (7 2) (8 2) (8 3) (8 4)
> (7 4) (6 4) (5 4)
>  (4 4) (4 5) (3 5) (3 6) (4 6))
>
> Cheers, Mariano

But i want a way that don't involve things like this: (make-hash-
table :test #'equal)))

Regards,
Alexandre
```
 0
Reply thot4ever (8) 6/10/2008 2:20:59 PM

```On Jun 10, 3:19 pm, Alexandre Almeida <thot4e...@gmail.com> wrote:
> On Jun 10, 3:12 pm, Raffael Cavallaro <raffaelcavallaro@pas-d'espam-
>
> s'il-vous-plait-mac.com> wrote:
> > On 2008-06-10 09:31:16 -0400, Alexandre Almeida <thot4e...@gmail.com> said:
>
> > Assuming that your data will always take the form of a list of two
> > element lists:
>
> > > (defun apaga-repetidos (lista)
> > >   (let ((p (first lista))
> > >         (r (rest lista)))
> > >     (if (null lista)
> > >         nil
> > >     (if (equal p r)
>
> > ^^^^^^^^^^^^^^^^^^^^^
> > are these really what you want to compare here?
>
> I want to compare a list that is always like this:
>
> '((1 2) (2 2) (3 2) (4 2) (5 2) (6 2) (4 2) (3 2))
>
> And i want to remove the repeated elements
>
> > Don't you really want to compare (first p) and (second p)?
>
> > >         (apaga-repetidos r)
> > >       (cons p (apaga-repetidos r))))))

Sorry...

I have this list --> '((1 2) (2 2) (3 2) (4 2) (5 2) (6 2) (4 2) (3
2))
and i want to remove duplicate entries.

I have this function:

(defun iguais(x y)
(if (and (equal (car x) (car y)) (equal (cadr x) (cadr y)))
t
nil
)
)

That give T if x and y are equals (x = '(1 2), y = '(1 2) --> t)

But i'm with difficult to build a function that remove the repeated
elements!!

I have something like this:

(defun apaga-repetidos-2 (lista x)
(if (null lista)
nil
(let ((p (first lista))
(r (rest lista)))
(if (iguais p (car r))
(apaga-repetidos-2 r x)
(cons p (apaga-repetidos-2 lista x))))))

But don't work!!

Best regards,
Alexandre Almeida
```
 0
Reply thot4ever (8) 6/10/2008 2:29:31 PM

```On Jun 10, 3:31 pm, Alexandre Almeida <thot4e...@gmail.com> wrote:
> I have this piece of code, that sould delete all the repeated
> elements from a list :

First of all, are you aware of REMOVE-DUPLICATES?

CL-USER> (remove-duplicates '((1 2) (2 2) (3 2) (4 2) (5 2) (6 2) (4
2) (3 2))
:test #'equal)
((1 2) (2 2) (5 2) (6 2) (4 2) (3 2))

All best,
Tayssir
```
 0
Reply tayssir.john (114) 6/10/2008 2:30:31 PM

```On Jun 10, 3:30 pm, Tayssir John Gabbour <tayssir.j...@googlemail.com>
wrote:
> On Jun 10, 3:31 pm, Alexandre Almeida <thot4e...@gmail.com> wrote:
>
> > I have this piece of code, that sould delete all the repeated
> > elements from a list :
>
> First of all, are you aware of REMOVE-DUPLICATES?
>
> CL-USER> (remove-duplicates '((1 2) (2 2) (3 2) (4 2) (5 2) (6 2) (4
> 2) (3 2))
>                             :test #'equal)
> ((1 2) (2 2) (5 2) (6 2) (4 2) (3 2))
>
> All best,
> Tayssir

Yes, I have... But i need to build that function, for a school work :(

Regards,
Alexandre
```
 0
Reply thot4ever (8) 6/10/2008 2:36:24 PM

```On Jun 10, 9:36 am, Alexandre Almeida <thot4e...@gmail.com> wrote:
> i need to build that function, for a school work :(

So you're cheating?

--Dan

------------------------------------------------
http://www.prairienet.org/~dsb/

cl-match:  expressive pattern matching in Lisp
http://common-lisp.net/project/cl-match/
```
 0
Reply sogwaldan (120) 6/10/2008 2:47:45 PM

```On Jun 10, 3:47 pm, danb <sogwal...@gmail.com> wrote:
> On Jun 10, 9:36 am, Alexandre Almeida <thot4e...@gmail.com> wrote:
>
> > i need to build that function, for a school work :(
>
> So you're cheating?
>
> --Dan
>
> ------------------------------------------------http://www.prairienet.org/~dsb/
>
> cl-match:  expressive pattern matching in Lisphttp://common-lisp.net/project/cl-match/

No I'm not cheating... If i'm cheating i have post all of my work
here!!

But i'm going to use the remove-duplicates...

Tanks all for the help!!

Regards,
Alexandre
```
 0
Reply thot4ever (8) 6/10/2008 3:15:49 PM

```Alexandre Almeida wrote:
> On Jun 10, 3:30 pm, Tayssir John Gabbour <tayssir.j...@googlemail.com>
> wrote:
>> On Jun 10, 3:31 pm, Alexandre Almeida <thot4e...@gmail.com> wrote:
>>
>>> I have this piece of code, that sould delete all the repeated
>>> elements from a list :
>> First of all, are you aware of REMOVE-DUPLICATES?
>>
>> CL-USER> (remove-duplicates '((1 2) (2 2) (3 2) (4 2) (5 2) (6 2) (4
>> 2) (3 2))
>>                             :test #'equal)
>> ((1 2) (2 2) (5 2) (6 2) (4 2) (3 2))
>>
>> All best,
>> Tayssir
>
> Yes, I have... But i need to build that function, for a school work :(

(defun rem-duplicates (list)
(loop for (first . rest) on (append list list)
unless (member first (reverse rest) :test #'equal)
collect first))

Pascal

--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
```
 0
Reply pc56 (3930) 6/10/2008 4:27:34 PM

```On Jun 10, 4:29 pm, Alexandre Almeida <thot4e...@gmail.com> wrote:
> I have something like this:
>
> (defun apaga-repetidos-2 (lista x)
>    (if (null lista)
>        nil
>        (let ((p (first lista))
>              (r (rest lista)))
>          (if (iguais p (car r))
>              (apaga-repetidos-2 r x)
>                (cons p (apaga-repetidos-2 lista x))))))

You're close.

For one thing, let's get rid of X:

(defun apaga-repetidos (lista)
(if (null lista)
nil
(let ((p (first lista))
(r (rest lista)))
(if (equal p (car r))
(apaga-repetidos r)
(cons p (apaga-repetidos list))))))

Now note that there's a small error. On the very last line, you call
(apaga-repetidos list)
which will infinitely recurse.

Also,
(equal p (car r))
will only work if all the duplicates are next to each other. Consider
using the MEMBER function, giving the right :TEST argument.

(BTW, I don't consider it "cheating," nor is it my place to enforce
absurd school policy even if it were. ;) If you want, I can send the
solution, but perhaps you'll prefer to figure it out...)

Tayssir
```
 0
Reply tayssir.john (114) 6/10/2008 5:37:57 PM

```On Jun 10, 11:27 am, Pascal Costanza <p...@p-cos.net> wrote:
> ... (append list list) ... (reverse rest) ...

What's that supposed to do?  If you're trying to
order elements by first occurance:

(defun rem-dupes (orig &key (test #'eql))
(let* ((list (copy-list orig))
(cell list))
(loop
(unless cell (return list))
(setf (cdr cell) (delete (car cell) (cdr cell) :test test)
cell (cdr cell)))))

--Dan

------------------------------------------------
http://www.prairienet.org/~dsb/

cl-match:  expressive pattern matching in Lisp
http://common-lisp.net/project/cl-match/
```
 0
Reply sogwaldan (120) 6/10/2008 6:01:06 PM

```Alexandre Almeida <thot4ever@gmail.com> writes:

> On Jun 10, 3:47 pm, danb <sogwal...@gmail.com> wrote:
>> On Jun 10, 9:36 am, Alexandre Almeida <thot4e...@gmail.com> wrote:
>>
>> > i need to build that function, for a school work :(
>>
>> So you're cheating?
>
> No I'm not cheating... If i'm cheating i have post all of my work
> here!!
>
> But i'm going to use the remove-duplicates...

Well if the purpose of your exercise is to implement
remove-duplicates, it won't do to use cl:remove-duplicates.  This
would be cheating.

First, while I understand English is not your native tongue, you must
be clearer on the concepts and terminology.

When you say that you want to remove duplicate entries, it's not the
same thing than when you say that you want to remove the repeated
elements.

In the sequence:

(1 2 3 2 3 2)

the repeated elements are 2 and 3.  When we remove them, we're left with:

(1)

But the duplicate elements are the 2, 3 and 2 that follow 1 2 3.  When
you remove those duplicates, you're left with:

(1 2 3)

If you can express what you want more precisely, you should be able to
come with a formal definition of your function, and then translating
this formal definition in lisp should be trivial.

And what reason would there be to refuse a solution using hash tables?

--
__Pascal Bourguignon__                     http://www.informatimago.com/

"What is this talk of "release"?  Klingons do not make software
"releases".  Our software "escapes" leaving a bloody trail of
designers and quality assurance people in its wake."
```
 0
Reply pjb (7870) 6/10/2008 6:43:47 PM

```danb wrote:
> On Jun 10, 11:27 am, Pascal Costanza <p...@p-cos.net> wrote:
>> ... (append list list) ... (reverse rest) ...
>
> What's that supposed to do?

Pascal

--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
```
 0
Reply pc56 (3930) 6/10/2008 7:27:05 PM

```Alexandre Almeida <thot4ever@gmail.com> writes:

> Hi everyone!
>
> I have this piece of code, that sould delete all the repeated elements
> from a list :
>
> (defun apaga-repetidos (lista)
>   (let ((p (first lista))
>         (r (rest lista)))
>     (if (null lista)
>         nil
>     (if (equal p r)
>         (apaga-repetidos r)
>       (cons p (apaga-repetidos r))))))
>
> > : (apaga-repetidos '((1 2) (2 2) (3 2) (4 2) (5 2) (6 2) (7 2) (8 2) (8 3) (8 4) (7 4) (6 4) (5 4) (4 4) (4 5) (3 5) (3 6) (4 6) (4 5) (4 4) (5 4) ))
>
>
> But i cant��t put this to work. Someone can help me?

Well, there's always

(remove-duplicates lista :test #'equal)

This typically isn't very smart and uses an N^2 algorithm, but it is the

However, it will be a worthwhile learning experience to build your own.

--
Thomas A. Russ,  USC/Information Sciences Institute

```
 0
Reply tar (1630) 6/10/2008 7:33:32 PM

```Pascal Costanza <pc@p-cos.net> writes:

> Alexandre Almeida wrote:
> > Yes, I have... But i need to build that function, for a school work :(
>
> (defun rem-duplicates (list)
>    (loop for (first . rest) on (append list list)
>          unless (member first (reverse rest) :test #'equal)
>          collect first))

That's slightly evil.
<insert maniacal laughter>

--
Thomas A. Russ,  USC/Information Sciences Institute

```
 0
Reply tar (1630) 6/10/2008 7:35:42 PM

```On Jun 10, 6:27 pm, Pascal Costanza <p...@p-cos.net> wrote:
> > Yes, I have... But i need to build that function, for a school work :(
>
> (defun rem-duplicates (list)
>    (loop for (first . rest) on (append list list)
>          unless (member first (reverse rest) :test #'equal)
>          collect first))

Isn't it terrible to crap all over a nice short LOOP solution?

;)

Tayssir
```
 0
Reply tayssir.john (114) 6/10/2008 9:23:55 PM

```On 2008-06-10 10:29:31 -0400, Alexandre Almeida <thot4ever@gmail.com> said:

> Sorry...
>
>
> I have this list --> '((1 2) (2 2) (3 2) (4 2) (5 2) (6 2) (4 2) (3
> 2))
> and i want to remove duplicate entries.

Ok, I thought when you said "repeated entries" you meant sublists like
(2 2) or (3 3). I didn't think you meant remove-duplicates since, as
others have pointed out, that's part of the standard language.

```
 0

```Pascal Costanza wrote:

> Alexandre Almeida wrote:
> > On Jun 10, 3:30 pm, Tayssir John Gabbour <tayssir.j...@googlemail.com>
> > wrote:
> >>On Jun 10, 3:31 pm, Alexandre Almeida <thot4e...@gmail.com> wrote:
> > >
> > > > I have this piece of code, that sould delete all the repeated
> > > > elements from a list :
> > > First of all, are you aware of REMOVE-DUPLICATES?
> > >
> >>CL-USER> (remove-duplicates '((1 2) (2 2) (3 2) (4 2) (5 2) (6 2) (4
> > > 2) (3 2))
> >>                            :test #'equal)
> > > ((1 2) (2 2) (5 2) (6 2) (4 2) (3 2))
> > >
> > > All best,
> > > Tayssir
> >
> > Yes, I have... But i need to build that function, for a school work :(
>
> (defun rem-duplicates (list)
>   (loop for (first . rest) on (append list list)
>         unless (member first (reverse rest) :test #'equal)
>         collect first))
>

Arc:

(def remove-duplicates (lst)
(map car (tablist (counts lst))))

(remove-duplicates '((1 2) (2 2) (3 2) (4 2) (5 2) (6 2) (4 2) (3 2)))
==>
((5 2) (3 2) (4 2) (2 2) (1 2) (6 2))
```
 0
Reply w_a_x_man (3243) 5/28/2011 11:27:31 AM

```WJ wrote:

> Pascal Costanza wrote:
>
> > Alexandre Almeida wrote:
> > > On Jun 10, 3:30 pm, Tayssir John Gabbour <tayssir.j...@googlemail.com>
> > > wrote:
> > >>On Jun 10, 3:31 pm, Alexandre Almeida <thot4e...@gmail.com> wrote:
> > > >
> > > > > I have this piece of code, that sould delete all the repeated
> > > > > elements from a list :
> > > > First of all, are you aware of REMOVE-DUPLICATES?
> > > >
> > >>CL-USER> (remove-duplicates '((1 2) (2 2) (3 2) (4 2) (5 2) (6 2) (4
> > > > 2) (3 2))
> > >>                            :test #'equal)
> > > > ((1 2) (2 2) (5 2) (6 2) (4 2) (3 2))
> > > >
> > > > All best,
> > > > Tayssir
> > >
> > > Yes, I have... But i need to build that function, for a school work :(
> >
> > (defun rem-duplicates (list)
> >   (loop for (first . rest) on (append list list)
> >         unless (member first (reverse rest) :test #'equal)
> >         collect first))
> >
>
> Arc:
>
> (def remove-duplicates (lst)
>   (map car (tablist (counts lst))))
>
> (remove-duplicates '((1 2) (2 2) (3 2) (4 2) (5 2) (6 2) (4 2) (3 2)))
>   ==>
> ((5 2) (3 2) (4 2) (2 2) (1 2) (6 2))

(def remove-duplicates (lst)
(keys (counts lst)))

Jarc> (dedup '((1 2) (2 2) (3 2) (4 2) (5 2) (6 2) (4 2) (3 2)))
((1 2) (2 2) (3 2) (4 2) (5 2) (6 2))
```
 0
Reply w_a_x_man (3243) 5/28/2011 11:32:42 AM

20 Replies
37 Views

Similar Articles

12/13/2013 11:35:57 AM
[PageSpeed]

Similar Artilces:

How to copy only non-repeated lists elements to a single list using functors
Hi: I have a map<string, list<string> > and I need to copy the sublists items to a single list, filtering the repeated ones. I think it can be done using stl functors and adaptors, but I don't know how. Here's the example code using loops: void sublist_copy() { typedef pair<string,list<string> > map_string_list_pair; typedef map<string,list<string> > map_string_list; map_string_list m; list<string> l; pair<map_string_list::iterator, bool> i; i = m.insert(map_string_list_pair("list 1", list<string>())); ...

rule based program for "Deleting repeated members of a list."
Hi, I have a list s={a,b,c,c,d,e,e,f,g,g,g,h,a,b}; I need to write a program so that it reads the list and ignors repeated elements; so it outputs the following: RepeatRemover[s]={a,b,c,d,e,f,g,h,a,b}; I am looking for a rule-based program to do this! Any help would be greatly appreciated. C.S. I'm sure there are more elegant ways of doing what you want, but here is my take: In[1]:=list={a,b,c,c,d,e,e,f,g,g,g,h,a,b}; Delete[list, Position[ ListConvolve[ {-1,1}, list], 0]] Out[2]={a,b,c,d,e,f,g,h,a,b} HTH, Mark Mark R. Holt, BA, PhD, Room 3.28 M...

List of Atom or List of List??
how can detect some element of list is list o Atom?? for example when i try head (head p1) where p1=[[1,2],2] return 1 but when try head (head p1) where p1=[1,2] it returns Error plz help me..it my project and i have just 2 hours..:( i want to replace on Atom by another in list..for example: replace 1 2 [1,2] => [2,2] but sometime i have replace 1 2 [[1,2],2]=>[[2,2],2] i want to detect if first element of list is list then recurcively call head on that element.. is there any solutions?? On 8 Apr 2007 02:46:25 -0700, kheirandish.amin@gmail.com wrote: >how can detect some eleme...

lists of lists
I'm using C++ and I'm trying to create a list of a list and it won't let me create an iterator for it. if I do a list of an int, everything is fine. my syntax is list<list<string> > some_list; and my iterator would be someting like list<list>::Iterator blah; or maybe list<list<string> >::Iterator blah; ?? neither work, ofcourse. basicaly I'm trying to parse a text file, each line is token that contains tokens and I have a function that takes a string and returns the list of the tokens. so I have my the parent list to contain lists to t...

concatenate the elements in each list of a list of lists
I already asked a similar question, but encounter problems with python... How can I concatenate the elements in each list of a list of lists list_of_listsA = [['klas*', '*', '*'], ['mooi*', '*', '*', '*'], ['arm*', '*', '*(haar)']] wanted result: list_of_listsA = [['klas* * *'] ['mooi* * * *'] ['arm* * *(haar)']] Thanks a lot ! On Jul 23, 5:33=A0pm, antar2 <desoth...@yahoo.com> wrote: > I already asked a similar question, but encounter problems with > python... > How c...

Listings package / List of Listings / Layout
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi - I am trying to get the 'List of Listings' to look like the 'List of Figures' and 'List of Tables' but I don't know how. Both the LOF and LOT (inside the files .lof and .lot) use \addvspace {10\p@} in between the entries for each chapter, but the LOL (in file ..lol) does not do that, 'messing up' the design I want. I know this is a pretty minor thing and not really noticable but nice to have if it works. I'll live without a solution, but if anybody has something for me, it's appreciated. Tha...

list of ascii to list of chars, and list question
another simple exercise that i am trying to wrap my head around as i learn prolog: how would i convert the elements of a list from its ascii value to its char value. for example: [97,98,99,100 ] would become [a,b,c,d], if i had a set of facts, charvalue(X,Y), where X is its ascii value and Y is its char value? another question i had is it possible to append lists to itself, i.e if i had a list X = [1,2,3] and i wanted to append to it 4, is there anyway to do append(X, 4, X), so that it would return the original list X but with 4 added at the end? because what i am trying to do is read in a ...

List of lists
I'm doing some simple list-of-lists processing, where the inner lists are collections of field data from a database. I'm completely failing to see some mistake I've made, probably an obvious one. I can't post executable code because you can't replicate my environment (the database and so forth) but I'm posting a sample case and the console output from it, and you'll see where I'm stuck. (The example below is from ActiveState Perl but the same problem happens under Linux) # ------------------ tryit.pl -------------------------- #! /usr/bin/perl use stric...

Indexing list of lists
This may have been asked before but I can't find it. If I have a rectangular list of lists, say, l = [[1,10],[2,20],[3,30]], is there a handy syntax for retrieving the ith item of every sublist? I know about [i[0] for i in l] but I was hoping for something more like l[;0]. Hilde hildegarde_roth@yahoo.de (Hilde Roth) writes: > This may have been asked before but I can't find it. If I have > a rectangular list of lists, say, l = [[1,10],[2,20],[3,30]], is > there a handy syntax for retrieving the ith item of every sublist? > I know about [i[0] for i in l] but I was hopin...

lists of lists (newbie)
Lisp newbie asks . . . For various reasons, I need to process a bunch of terms with associated weights. In other words, I have things like: "foo" -> .8838 "bar" -> .2838 "bat" -> .2849 etc. Now, this seems like a natural for a hash table, and I can easily get one set up. However, I need to return the the results sorted by the value. I can't use the value as the key, because I can't guarantee the uniqueness of the value. There doesn't seem to be a function called "sort-by-value", and so I'm essentially trying to build one ...

exclude list from list
Hello is there a quick way to produce a list of emails that subtracts a small list emails from a big list. Thanks. On Oct 17, 12:02 pm, joe <jcha...@gmail.com> wrote: > Hello is there a quick way to produce a list of emails that subtracts > a small list emails from a big list. Thanks. shove the big list in a hash, then for each item in the small list, delete it from the hash. On Oct 17, 12:02 pm, joe <jcha...@gmail.com> wrote: > Hello is there a quick way to produce a list of emails that subtracts > a small list emails from a big list. Thanks. \$ perldoc -q "d...

Module: list to list of trees
Hi, I have got the following csv-file: x1 a1 a1 b1 x2 a1 a1 b2 a2 c2 a2 c1 x1 a2 and i need a list of trees: x1 (root 1) a1 (child 1.1) b1 (child 1.1.1) b2 (child 1.1.2) a2 (child 1.2) c2 (child 1.2.1) c1 (child 1.2.2) x2 (root 2) a1 and so on b1 b2 Does a module already exists, allowing this transformation? -Philip erik.klein@t-online.de wrote: > Hi, Hi erik, > > I have got the following csv-file: > x1 a2 > > and i need a list of trees: > > > Does a module already exists, allowing this t...

list of lists from tk table
whats the best way to get a list of lists from a variable associated with a tk table? usually with a tk table you have a variable associated with it, i.e. var(1,1) = "dogs" var(1,2) = 100 var(2,1) = "cats" var(2,2) = 200 how do you obtain a list of lists of the data, i.e. mylist = { {dogs 100} {cats 200} } thanks, Sean Not sure if this is the best way, and if it really answers your question, but you could try something like: ..table selection set 0,0 end # or if you know the exact indices tk_tableCopy .table set mylist [clipboard get] HTH, --brett p.s. this ...

list.__len__() or len(list)
which one is better? and why? __len__() is a built-in function of the list object and is updated along with the list object elements and will be useful incase the list is very huge. len() is an external method again, which may require the processing cycles again. Is it right? On May 13, 6:57=A0pm, Nikhil <mnik...@gmail.com> wrote: > which one is better? and why? > > __len__() is a built-in function of the list object and is updated along > with the list object elements and will be useful incase the list is very > huge. > > len() is an external method again, wh...

read file into list of lists
Hello, I can not find out how to read a file into a list of lists. I know how to split a text into a list sentences = line.split(\n) following text for example should be considered as a list of lists (3 columns and 3 rows), so that when I make the print statement list[0] [0], that the word pear appears pear noun singular books nouns plural table noun singular Can someone help me? Thanks --nextPart1337499.xzdZJJmreI Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8Bit Hello, A way to do it =============================================================== from _...

RE: looping through a list of lists.
> From: saoirse_79 [SMTP:saoirse_79@yahoo.com] > I have a list of lists as follows: > [['-', '-', '-', '-', '-', '-', '-', 'K', 'S', 'A', 'K'], > ['-', '-', '-', '-', 'L', 'Q', 'Q', 'T', 'N', 'S', 'E'], > ['T', 'L', 'E', 'E', 'L', 'M', 'K', 'L', 'S', 'P', 'E']] > I want to be able to read each character and compare...

index of list of lists #2
yes, there's a thread with the same title, but I believe mine is more=20 appropriate title. so, as much as I search on the web, read manuals, tutorials, mail-lists=20 (including this one) I cannot figure it out how to search a string in a=20 list of lists. like this one: someList =3D [['somestring', 1, 2], ['oneother', 2, 4]] I want to search "somestring" in someList which is in practice a list=20 of aprox. 200 lists. (hey, I'm a newbie python programmer, don't judge=20 me). is the list.index the wrong approach? should I use numpy, numarray, something el...

List.size() != List.capacity();
Hi! I need a list to which I progressively add data to - at random indices. So I set a List which ensures to have enough space for all items: list = new ArrayList(max); This does internally create an Object[] array of size <max>. Unfortunately I cannot add at arbitrary indices as size() reflects only the count of items already in the list and any access to an index greater than size() throws an IndexOutOfBoundsException - despite the index is not out bounds of the backing Object[] array. So i do have to manually "initiliaze" the list *again*: for (int i = 0; i < ...

converting a list to keyed list
I need to convert the following list to a keyed list, so that the key value pair can be parsed at ease. Please let me know the easiest way - List - string " Adjacency cacSipAdj2 (SIP) Status: Attached Signaling address: 88.88.127.113:5060 Signaling-peer: 88.88.127.114:5060 Force next hop: No Account: CAC-Sip-Adj2 Group: In header profile: Default Out header profile: Default In method profile: Default ...

Makefiles and list enviroment list
HI A question, can you access the system environment list in a Makefile ? (if so how ). The reason is as follows, I have a cvs component which has various useful routines (something like a toolbox, but I don't want to build a custom lib if I can help it). What I want to is set some custom environment variable eg SET CUSTOM_COMPONENT=~/common/mysq asnd in the my Makefile I can use sql_interface.o: sql_interface.c \$(CC) ...... \$(CUSTOM_COMPONENT)/slq_common.o Is this possible ? Thanks David LeTubs wrote: > HI > > A question, can you access the sy...