Kent Johnson wrote:
[..]
Why not just return the value from the function and pass it up the
call chain? If a call fails return None. Something like this:
That's what I ended up doing but the first thing occurred to me and I
was just wondering if there's any production code that relies on the
On Sat, Jul 4, 2009 at 12:09 PM, Steven Buck wrote:
> I've used a module (StataTools) from (http://presbrey.mit.edu/PyDTA ) to get
> a Stata ".dta" file into Python. In Stata the data set is an NXK matrix
> where N is the number of observations (households) and K is the number of
> variables.
> I
Noufal Ibrahim wrote:
Kent Johnson wrote:
[..]
Why not just return the value from the function and pass it up the
call chain? If a call fails return None. Something like this:
That's what I ended up doing but the first thing occurred to me and I
was just wondering if there's any production co
The problem this time is, given an amount of US currency in cents
(and less than a dollar), to print out a description of the coins
needed to represent it, using the smallest number of coins. E.g.:
How many cents this time? 59
2 quarters, 1 nickel and 4 pennies.
How many cents this time? 55
2 qu
Angus Rodgers wrote:
[..]
This feels like a bit of a cheat, as if I am trying to program in
Python as if it were some other more familiar language. Should I
have coded this differently?
I can't offer anything concrete but here are some things that occur to
me at a glance.
0. You can try to
[Angus Rogers, suffering eval-angst]
> ...
> On the other hand, so long as I AM only executing the function
> myself, I am no more at risk than I already am every single time
> I type a command into a Python interpreter, of any description.
> (A somewhat Existentialist thought, perhaps! Virtual su
On Sunday 05 July 2009, Noufal Ibrahim wrote:
> Kent Johnson wrote:
> [..]
>
> > Why not just return the value from the function and pass it up
> > the call chain? If a call fails return None. Something like this:
>
> That's what I ended up doing but the first thing occurred to me and
> I was just
On Sun, Jul 5, 2009 at 2:48 PM, Angus Rodgers wrote:
> for i in range(LEN - 1):
> (count[i], amnt) = divmod(amnt, value[i])
How about this:
counts = []
for val in value:
count, amnt = divmod(amnt, val)
counts.append(count)
> This feels like a bit of a cheat, as if I am trying to program i
"Angus Rodgers" wrote
as keys? Is it possible to guarantee a sequence in which the keys
of a dictionary are iterated through?
Indirectly yes:
for key in sorted( dct ):
print key
I would definitely tend to go with a dictionary for the
denominations/values in this case (Actually I'd
Hi Python Tutors:
I have a data structure that looks like:
>>> test=[[1,2,3],[4,5,6],[7,8,9]]
I want to define a new variable that captures the second element of each
sublist from above:
>>> testvar2 = []
Next I try to capture the aforementioned elements:
>>> for i in len(test):
t
On Sun, 5 Jul 2009 18:49:32 -0400, Kent Johnson wrote:
>On Sun, Jul 5, 2009 at 2:48 PM, Angus Rodgers wrote:
>
>> for i in range(LEN - 1):
>> (count[i], amnt) = divmod(amnt, value[i])
Incidentally, I forgot to quote the next line:
count[-1] = m
Of course, this is much better incorporated int
Read your error message... It highlighted the first line of your for
loop ansd said ints aren't iterable. len(list) returns an integer. You
want a list of items... for i in range(len(list)):
On 7/5/09, Steven Buck wrote:
> Hi Python Tutors:
>
> I have a data structure that looks like:
>
test
On Mon, 06 Jul 2009 01:02:10 +0100, I hastily wrote:
>Incidentally, I forgot to quote the next line:
>
>count[-1] = m
That was copied-and-pasted from an older version of the program,
with less descriptive identifiers. 'm' should be 'amnt'.
>Of course, this is much better incorporated into the l
2009/7/5 Steven Buck :
for i in len(test):
> testvar2.append(test[i][2])
>
> I want testvar2 = [2,5,8] but instead I get the following error message:
>
> Traceback (most recent call last):
> File "", line 1, in
> for i in len(test):
> TypeError: 'int' object is not iterable
In [1]: test=[[1,2,3],[4,5,6],[7,8,9]]
In [3]: testvar2 = []
In [16]: for i in range(len(test)):
: testvar2.append(test[i][1])
:
:
In [17]: testvar2
Out[17]: [2, 5, 8]
Robert
On Sun, 2009-07-05 at 15:57 -0700, Steven Buck wrote:
> Hi Python Tutors:
>
> I ha
> if name in plural:
> name = plural[name]
> else:
> name += 's'
This could be written more cleanly (although arguably not as readably) as
name = plural.get(name, name + "s")
d.get(key, default) returns the value from d mapped to
Angus Rodgers wrote:
The problem this time is, given an amount of US currency in cents
(and less than a dollar), to print out a description of the coins
needed to represent it, using the smallest number of coins. E.g.:
How many cents this time? 59
2 quarters, 1 nickel and 4 pennies.
How many c
2009/7/6 Steven Buck :
> Thanks for the previous responses. This isn't homework--I'm beyond
> coursework, although I am a newbie to Python (and I've never had to do much
> real programming since I've just used Stata for econometric analysis). I'm
> testing Python as a more powerful alternative to
Hello all, this is my first time using a mailing list, so I'm not sure if
I'm doing this right! Anyway, I have a wee bit of a problem. I've recently
completed watching a Youtube video series on Python 2.6 by thenewboston
which helped me a TON with learning Python's syntax and how to use some of
t
19 matches
Mail list logo