470,644 Members | 1,204 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,644 developers. It's quick & easy.

Going crazy...

Hello all,

I'm 100% sure that I saw an example which looked something like this
recently:
a=(1, 2, 3, 4, 5, 6)
b=(2, 3, 6)
a - b

(1, 4, 5)

The only new language I have been involved in lately is Python. Is my
memory failing me, or have I seen such an Python-example somewhere? If
so: Where; or more importantly: How does it work?

I just tried typing the above in Python, and it - obviously - doesn't
work, so it must be some other syntax.
Jul 19 '05 #1
5 982
Jan Danielsson wrote:
Hello all,

I'm 100% sure that I saw an example which looked something like this
recently:
a=(1, 2, 3, 4, 5, 6)
b=(2, 3, 6)
a - b

(1, 4, 5)

The only new language I have been involved in lately is Python. Is my
memory failing me, or have I seen such an Python-example somewhere? If
so: Where; or more importantly: How does it work?

I just tried typing the above in Python, and it - obviously - doesn't
work, so it must be some other syntax.

Not with tuples, lists or dictionaries. However a more recent addition
to the language is Sets, and they support set differences:
from sets import Set
Set([1,2,3,4,5,6]) - Set([2,3,6])

Set([1, 4, 5])
Gary Herron

Jul 19 '05 #2
Jan Danielsson wrote:
Hello all,

I'm 100% sure that I saw an example which looked something like this
recently:

a=(1, 2, 3, 4, 5, 6)
b=(2, 3, 6)
a - b
(1, 4, 5)

The only new language I have been involved in lately is Python. Is my
memory failing me, or have I seen such an Python-example somewhere? If
so: Where; or more importantly: How does it work?

I just tried typing the above in Python, and it - obviously - doesn't
work, so it must be some other syntax.


Try sets:
a=set([1,2,3,4,5,6])
b=set([2,3,6])
a-b set([1, 4, 5])


--Irmen
Jul 19 '05 #3
On Mon, 13 Jun 2005 20:52:43 -0400, Gary Herron wrote
(in article <42**************@islandtraining.com>):
Jan Danielsson wrote:
Hello all,

I'm 100% sure that I saw an example which looked something like this
recently:
> a=(1, 2, 3, 4, 5, 6)
> b=(2, 3, 6)
> a - b
>
>

(1, 4, 5)

The only new language I have been involved in lately is Python. Is my
memory failing me, or have I seen such an Python-example somewhere? If
so: Where; or more importantly: How does it work?

I just tried typing the above in Python, and it - obviously - doesn't
work, so it must be some other syntax.

Not with tuples, lists or dictionaries. However a more recent addition
to the language is Sets, and they support set differences:
>>> from sets import Set
>>> Set([1,2,3,4,5,6]) - Set([2,3,6])

Set([1, 4, 5])
Gary Herron


Looks like something that might be part of an example of class operator
overloading??? But I'm not far enough along to quickly show a sample if such
is possible.

Lee C
Jul 19 '05 #4
Gary Herron wrote:
[---]
I just tried typing the above in Python, and it - obviously - doesn't
work, so it must be some other syntax.

Not with tuples, lists or dictionaries. However a more recent addition
to the language is Sets, and they support set differences:
from sets import Set
Set([1,2,3,4,5,6]) - Set([2,3,6])

Set([1, 4, 5])


That's it! Thanks; I knew I had seen it. That's a pretty cool
feature; which I have use for in a library I'm writing.
Jul 19 '05 #5
Jan Danielsson wrote:
Gary Herron wrote:
... a more recent addition to the language is Sets, ...
>from sets import Set
>Set([1,2,3,4,5,6]) - Set([2,3,6])


Set([1, 4, 5])


If you are using 2.4 or later, you can simply use "set" without
importing anything.

set(['apple', 'orange', 5]) - set([5])

--Scott David Daniels
Sc***********@Acm.Org
Jul 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Richard | last post: by
6 posts views Thread by Fresh Air Rider | last post: by
3 posts views Thread by Larry Tate | last post: by
7 posts views Thread by Miguel Dias Moura | last post: by
6 posts views Thread by thomas.luce | last post: by
15 posts views Thread by manstey | last post: by
3 posts views Thread by Johnny JŲrgensen | last post: by
1 post views Thread by Korara | last post: by
reply views Thread by warner | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.