Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / Python

Author
Message
Michael P
18
Years of Service
User Offline
Joined: 6th Mar 2006
Location: London (UK)
Posted: 27th Oct 2012 15:22
I have just started learning Python coming form a Java and C++ background.

The first thing I notice is that the Set data structure is missing a get method, so I can't retrieve items from my set without iterating through it? I don't want to iterate through it for performance reasons.

I would have expected this to be a hash table under the hood, so it should be trivial to have a get method, so why isn't there one?

Essentially what I want is the equivalent to a java HashSet; I am thinking I might need to build a class on top of a python dict to achieve the same functionality, but surely there already exists something that does what I want!

The Wilderbeast
18
Years of Service
User Offline
Joined: 14th Nov 2005
Location: UK
Posted: 27th Oct 2012 16:12 Edited at: 27th Oct 2012 16:26
[EDIT] Forget that - I skipped past the 'Set' part.

If you want to retrieve an item from your set, I am assuming you intend to modify its value? In which case the List data type would be much better suited.

For a list you can use the index() method.



http://docs.python.org/tutorial/datastructures.html

If you want to test simply whether a value is in your Set then you can use the 'in' keyword.




I think I may not have fully understood what your intention was, so forgive me if I'm pointing out the obvious!

Login to post a reply

Server time is: 2024-05-08 00:12:27
Your offset time is: 2024-05-08 00:12:27