[Tutor] Sets question

boB Stepp robertvstepp at gmail.com
Wed Apr 26 22:02:26 EDT 2017


On Wed, Apr 26, 2017 at 8:34 PM, Phil <phil_lor at bigpond.com> wrote:
> On Wed, 26 Apr 2017 18:56:40 -0600
> Mats Wichmann <mats at wichmann.us> wrote:
>
>> On 04/26/2017 06:33 PM, Phil wrote:
>> > Another question I'm afraid.
>> >
>> > If I want to remove 1 from a set then this is the answer:
>> >
>> > set([1,2,3]) - set([1])
>> >
>> > I had this method working perfectly until I made a change to cure
>> > another bug.
>> >
>> > So, I have a set represented in the debugger as {1,2,3} and again I
>> > want to remove the one. Only this time the one set is represented
>> > as {'1'} and, of course {'1'} is not in the set {1,2,3}.
>> >
>> > Ideally, I would like {'1'} to become {1}. Try as I may, I have not
>> > discovered how to remove the '' marks. How do I achieve that?
>> >
>>
>> A little confused... why not just create it the way you want it? How
>> do you end up with {'1'} ?
>
> Thank you for your quick replies Mats and erky.
>
> I use .get() to retrieve a number from an entry box, which looks like {1} (no '' marks). If I then turn this number into a set then the result is {'1'}.
>
> num = self.entry_grid[row][col].get()

I would think that it is here that you would want to do the
string-to-integer conversion.  The contents of an entry box are
strings, not integers or floats.

num = int(self.entry_grid[row][col].get())

It is a similar situation when using input() to get user input.  You
need to convert the 'number-like' strings to integers (or floats).

-- 
boB


More information about the Tutor mailing list