Unions,Intersections, and Difference...not in sequence

31 views
Skip to first unread message

Robert Cressman

unread,
Sep 5, 2014, 8:03:54 PM9/5/14
to vim...@googlegroups.com
I entered the following code...

S1 = set([3, 5, 6, 10, 11, 100])
S2 = set([1, 3, 5, 6, 11, 15])
print(S1 | S2)
print(S1 & S2)
print(S1 - S2)

However, when it prints out, the resulting numbers are not sequential, which I believe they should be. Anyone have an idea what the problem is?

Charles E Campbell

unread,
Sep 5, 2014, 11:08:09 PM9/5/14
to vim...@googlegroups.com
Well, I changed that first line to "let S1=..." but I get

E117: Unknown function: set
E15: Invalid expression: set([3, 5, 6, 10, 11, 100])

I'm using vim, huge, 7.4.430 .

Regards,
Chip Campbell



Bob

unread,
Sep 5, 2014, 11:56:46 PM9/5/14
to vim...@googlegroups.com
My coding works without error, it just does not return the numbers in upward incrementation - just randomly.


Sent from my Verizon Wireless 4G LTE smartphone
--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to a topic in the Google Groups "vim_use" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_use/xDE7YWFdTQA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vim_use+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

LCD 47

unread,
Sep 6, 2014, 3:26:07 AM9/6/14
to vim...@googlegroups.com
Wrong forum. This list is about Vim, not Python.

/lcd

Tim Chase

unread,
Sep 6, 2014, 7:09:15 AM9/6/14
to vim...@googlegroups.com, bohi...@q.com
1) I'm pretty sure this isn't vim-script, as there's no set()
constructor that I know of

2) this looks an awful lot like Python, and sets in Python are
inherently unordered. If this is Python, you'd want to wrap the
contents of the print()s in sorted(). E.g., print(sorted(S1 - S2))

-tim







Bob

unread,
Sep 6, 2014, 9:22:24 AM9/6/14
to vim...@googlegroups.com
This code runs correctly in python. When I wrote it in vim is when problem occurs.


Sent from my Verizon Wireless 4G LTE smartphone


-------- Original message --------
From: LCD 47 <lcd...@gmail.com>
Date:09/06/2014 12:25 AM (GMT-07:00)
To: vim...@googlegroups.com
Cc:
Subject: Re: Unions,Intersections, and Difference...not in sequence

On 5 September 2014, Robert Cressman <bohi...@q.com> wrote:
> I entered the following code...
>
> S1 = set([3, 5, 6, 10, 11, 100])
> S2 = set([1, 3, 5, 6, 11, 15])
> print(S1 | S2)
> print(S1 & S2)
> print(S1 - S2)
>
> However, when it prints out, the resulting numbers are not sequential,
> which I believe they should be. Anyone have an idea what the problem
> is?

    Wrong forum.  This list is about Vim, not Python.

    /lcd

Robert A. Cressman

unread,
Sep 6, 2014, 10:01:26 AM9/6/14
to Tim Chase, vim...@googlegroups.com
That did it! Thanks!
Bob

Robert Cressman

unread,
Sep 6, 2014, 10:07:29 AM9/6/14
to vim...@googlegroups.com
On Saturday, September 6, 2014 12:26:07 AM UTC-7, LCD 47 wrote:

> On 5 September 2014, Robert Cressman wrote:
>
> > I entered the following code...
>
> >
>
> > S1 = set([3, 5, 6, 10, 11, 100])
>
> > S2 = set([1, 3, 5, 6, 11, 15])
>
> > print(S1 | S2)
>
> > print(S1 & S2)
>
> > print(S1 - S2)
>
> >
>
> > However, when it prints out, the resulting numbers are not sequential,
>
> > which I believe they should be. Anyone have an idea what the problem
>
> > is?
>
>
>
> Wrong forum. This list is about Vim, not Python.
>
>
>
> /lcd

Just an FYI, I coded it in Python and it worked correctly. When I did it in vim, I got the errors.

Boyko Bantchev

unread,
Sep 6, 2014, 11:41:01 AM9/6/14
to vim...@googlegroups.com
> Just an FYI, I coded it in Python and it worked correctly. When I did it in vim, I got the errors.

As you have been pointed out already, sets in Python are unordered
collections. So, what you call 'correctly' is what you expect to be
the norm, but in fact it isn't.
And what you perceive as an 'error' is not one, according to Python's
definition, and is certainly not anything Vim has to do with.
Reply all
Reply to author
Forward
0 new messages