Re: [Tutor] Iterate through dictionary values and remove item

2008-05-17 Thread Ricardo Araoz

Kent Johnson wrote:

On Thu, May 15, 2008 at 12:58 PM, GTXY20 <[EMAIL PROTECTED]> wrote:

I suspect that I need
to get a better handle on the difference between items() and iteritems() and
what situations would call for them respectively.


items() returns a list, iteritems() returns an iterator. If you don't
actually need an explicit list, iteritems() saves the cost of creating
it.


Having said that, Kent I am not 100 percent sure of what you menat when you
mention a two-level dict. Can you give me a very brief example?


Your dict d would look like this:
d={
1: {23A:[a,b,c,d],  24A:[b,c,d]},
2: {23A:[a,b], 24A:[a,b,c,d]}
  }



Lads...

>>> d={
... 1: {23A:[a,b,c,d],  24A:[b,c,d]},
... 2: {23A:[a,b], 24A:[a,b,c,d]}
...   }
  File "", line 2
1: {23A:[a,b,c,d],  24A:[b,c,d]},
  ^
SyntaxError: invalid syntax
>>>

Let's get a proper syntax for our data before attempting to process it.


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Is this the right way to create a

2008-06-23 Thread Ricardo Araoz

Kent Johnson wrote:

On Sun, Jun 22, 2008 at 3:50 PM, Zameer Manji <[EMAIL PROTECTED]> wrote:


I'm quite new to OOP, so forgive me if I am missing something obvious.
When you say that the User class should have a UserProfile as an
attribute, would it look something like this?

from lastfmapi import UserProfile
class User (object):
   def __init__:
   self.UserProfile = UserProfile('Bob')


Yes, that's about right. Of course 'Bob' should be an argument passed
to __init__()


Also what do you mean by 'accessors' for Neighbors ?


class User(object):
  ...
  def getNeighbors():
""" Returns a list of this user's neighbors """

and similar for getTopArtists(), etc.



A couple of caveats though.
Don't forget "self", it should be :

class User (object):
def __init__(self):
self.UserProfile = UserProfile('Bob')


Passing 'Bob' to __init__ would be :

class User (object):
def __init__(self, User='Bob'):
self.UserProfile = UserProfile(User)

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] arrays, while loops

2012-02-20 Thread Ricardo Araoz
El 20/02/12 13:42, Dave Angel escribió:
> I'm not sure who you are, but you forgot to include the list. 
> Therefore I'll forward this to the list, and add my comments about
> your suggestions.
>
> On 02/20/2012 11:31 AM, Ricardo Araoz wrote:
>> Untested :
>> while True:
>>  try:
>>  amounts[index] = int (input ("Enter an amount: "))
>>  amtinput = int (amounts)
>
> int() won't operate on a list.  Probably you meant it to operate on a
> string, but there are no strings in it, it's a list of ints.
>
>

sorry I meant :

amtinput = int (input ("Enter an amount: "))
amounts[index] = amtinput




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor