473,497 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Set literals

How about overloading curly braces for set literals, as in
aSet = {1,2,3}


- It is the standard mathematic set notation.
- There is no ambiguity or backwards compatibility problem.
- Sets and dicts are in many respects similar data structures, so why not share the same delimiter ?

*ducks*
Jul 18 '05 #1
3 2637
> - There is no ambiguity or backwards compatibility problem.

....at least if it wasn't for the empty set.. hmm...
Jul 18 '05 #2
+1 from me.

The other possible meaning for {1,2,3} would be {1:None,2:None,3:None},
but that is usually meant to be a set anyway (done with a dict).

So what is this: {1:2, 3, 4 } (apart from "nearly useless") ?

hmmm, thinking a bit more about this, it seems
you can build a set from a dict's keys, but not the other
way around. Is this odd, or what ?
a = set({1:0,2:0,3:0})
a set([1, 2, 3])
dict(a)

Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: cannot convert dictionary update sequence element #0 to a
sequence

Simon.

Jul 18 '05 #3
si***@arrowtheory.com> wrote:
+1 from me.

The other possible meaning for {1,2,3} would be {1:None,2:None,3:None},
but that is usually meant to be a set anyway (done with a dict).

So what is this: {1:2, 3, 4 } (apart from "nearly useless") ?
Syntax error; you'll have to decide whether you want a set or a dict.
hmmm, thinking a bit more about this, it seems
you can build a set from a dict's keys, but not the other
way around. Is this odd, or what ?
a = set({1:0,2:0,3:0})
a set([1, 2, 3])
dict(a) Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: cannot convert dictionary update sequence element #0 to a
sequence

Simon.


Nothing odd here. The set constructor takes an iterable, and dict.__iter__ iterates through the
dict's keys, so the set a in your example doesn't know anything about the dict's values. You can go
back and forth a set and a dict if you store the dict's items instead:
a = set({1:0,2:0,3:0}.iteritems())
a set([(1,0), (2,0), (3,0)]) dict(a)

{1:0, 2:0, 3:0}

Regards,
George
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
5473
by: nico | last post by:
In my python scripts, I use a lot of accented characters as I work in french. In order to do this, I put the line # -*- coding: UTF-8 -*- at the beginning of the script file. Then, when I need...
17
11195
by: Janice | last post by:
char* line = "abcd"; How to convert the line to upper case and print? Any option for printf to do this? Thanx
0
1235
by: Robin Tucker | last post by:
I'm localizing and need to find all string literals in my source code. I don't want to find any of the literals that will end up in resources however. As I don't use the "Me" keyword, I know...
6
2708
by: copx | last post by:
Can you / are you supposed to free() string literals which are no longer needed? In my case I've menu construction code that looks like this: menu_items = list_new(); list_add(menu_items,...
4
10961
by: Tyler Durden | last post by:
Hi: Just wondering if anyone can point me at some documentation for specifying literals with type in C#. I have searched for this a couple of times with no luck (found the VB.NET equivalent)....
15
2422
by: George Sakkis | last post by:
Although I consider dict(**kwds) as one of the few unfortunate design choices in python since it prevents the future addition of useful keyword arguments (e.g a default value or an orderby...
5
2160
by: bradeck | last post by:
A question recently came up of late in some interviewing techniques discussions and I vaguely remember this being an ANSI C++ related issue but cannot remember the specifics. Basically if you have...
27
2524
by: SasQ | last post by:
Hello. I wonder if literal constants are objects, or they're only "naked" values not contained in any object? I have read that literal constants may not to be allocated by the compiler. If the...
25
2995
by: Lennart Benschop | last post by:
Python has had the Decimal data type for some time now. The Decimal data type is ideal for financial calculations. Using this data type would be more intuitive to computer novices than float as its...
7
2248
by: lithiumcat | last post by:
Hi, I'm not yet very confident in my use of standard terminology, so please be kind if I'm mis-calling something, I will do my best no to make it again once pointed out. I'm wondering what is...
0
6991
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7196
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6878
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4897
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1405
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
649
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
286
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.