[Tutor] New to this list ....
Evert Rol
evert.rol at gmail.com
Fri Mar 30 17:19:34 CEST 2012
Hi and welcome Barry,
> One of the things I wanted to do is to use a four integer array to get four integers returned from a function. I ended up using what I think is a list. (I'm not really sure of the datatypes yet). This is what I did, and it works, but looks very inelegant to me:
>
> correct = 0
> match = 0
> wrong = 0
> results = [correct, match, wrong]
>
> results = getflag(flag_1, results)
> results = getflag(flag_2, results)
> results = getflag(flag_3, results)
> results = getflag(flag_4, results)
>
> Any thoughts?
Not sure. In the sense that you can "optimise" (refactor) it in the same way you could do with C. Eg:
results = [0, 0, 0]
flags = [0, 1, 2, 3]
for flag in flags:
results = getflag(flag, results)
I skipped the constant variables, but that should be clear.
The only non-C thing here is the loop, but I would think that's pretty clear. Note that flag takes on integer values here of course.
It could probably be done even more fancy/Pythonic, but I don't think there's a reason to do that.
Of course, depending on the getflag function itself, you may be able to rewrite things differently, but that's for another question I guess.
Cheers,
Evert
ps: I was going to comment on the indentation, but then spotted your other email. I am going to comment on the subject line though ;-), because that's not related to your actual question. A relevant subject helps a lot, among others for web searches from other people later one.
> Kind regards, Barry.
>
> --
> From Barry Drake - a member of the Ubuntu advertising team
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list