Send Tutor mailing list submissions to
tutor@python.org
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
[EMAIL PROTECTED]
You can reach the person managing the list at
[EMAIL PROTECTED]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Tutor digest..."
Today's Topics:
1. Re: String Replacement question (Wolfram Kraus)
2. python investment scheme assistance (Binish Huma Qadir)
3. Re: String Replacement question (Kent Johnson)
4. Re: String Replacement question (Moishy Gluck)
5. Re: python investment scheme assistance (Kent Johnson)
6. String Replacement Question (Kinuthia Muchane)
7. Re: String Replacement Question (Moishy Gluck)
----------------------------------------------------------------------
Message: 1
Date: Wed, 21 May 2008 12:11:28 +0200
From: Wolfram Kraus <[EMAIL PROTECTED]>
Subject: Re: [Tutor] String Replacement question
To: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Am 21.05.2008 11:35, Faheem schrieb:
Hi all,
How do I replace the same value multiple times without repeating the
same variable name/value repeatedly?
for ex.
some = 'thing'
print '%s %s %s %s' % (some,some,some,some)
in this case, my question is how do i replace "% (some,some,some)" with
something more concise?
thanks in advance,
Faheem
Hi!
Two possible solutions:
print "%s %s %s %s" % (tuple([some]*4))
print " ".join([some for x in range(4)])
HTH,
Wolfram
------------------------------
Message: 2
Date: Wed, 21 May 2008 19:35:01 +1000 (EST)
From: Binish Huma Qadir <[EMAIL PROTECTED]>
Subject: [Tutor] python investment scheme assistance
To: tutor@python.org
Message-ID:
<[EMAIL PROTECTED]>
Content-Type: text/plain; charset=UTF-8
Hi,
I'm doing a Investment implementation project where i need to use the
following data:
http://app.lms.unimelb.edu.au/bbcswebdav/courses/600151_2008_1/datasets/finance/asx_large.csv
I've been instructed to design an investment scheme in python.
The investment scheme i have chosen is based on investing in 3companies
with the highest dividend yield and lowest debt equity ratio.
The problem is that i dont know how to set up a python code that gives me
the top 3 companies with the above characterisics.
Your help would be much appreciated.
Thank you very much for your time.
Regards,
Binish
------------------------------
Message: 3
Date: Wed, 21 May 2008 06:36:30 -0400
From: "Kent Johnson" <[EMAIL PROTECTED]>
Subject: Re: [Tutor] String Replacement question
To: Faheem <[EMAIL PROTECTED]>
Cc: tutor@python.org
Message-ID:
<[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1
On Wed, May 21, 2008 at 5:35 AM, Faheem <[EMAIL PROTECTED]> wrote:
Hi all,
How do I replace the same value multiple times without repeating the
same variable name/value repeatedly?
for ex.
some = 'thing'
print '%s %s %s %s' % (some,some,some,some)
You can use named parameters, which moves the repetition to the format string:
In [24]: print '%(some)s %(some)s %(some)s %(some)s' % (dict(some=some))
thing thing thing thing
With multiple values, a common trick is to pass vars() or locals() as
the dict, giving the format access to all defined variables:
In [27]: a=1
In [28]: b=2
In [29]: print '%(a)s %(b)s' % vars()
1 2
If you literally need to repeat as in your example, you could do this:
In [26]: print '%s %s %s %s' % (4*(some,))
thing thing thing thing
Kent
------------------------------
Message: 4
Date: Wed, 21 May 2008 07:04:16 -0400
From: "Moishy Gluck" <[EMAIL PROTECTED]>
Subject: Re: [Tutor] String Replacement question
To: tutor@python.org
Message-ID:
<[EMAIL PROTECTED]>
Content-Type: text/plain; charset="iso-8859-1"
Some other solutions might be
animal = 'cat'
" ".join((animal, ) * 4)
'cat cat cat cat'
animal = 'cat'
print " ".join((animal, ) * 4)
cat cat cat cat
#If you need the string injected into another string
print "My %s's name is ginger." % (" ".join((animal,) * 4))
My cat cat cat cat's name is ginger.
On Wed, May 21, 2008 at 6:36 AM, Kent Johnson <[EMAIL PROTECTED]> wrote:
On Wed, May 21, 2008 at 5:35 AM, Faheem <[EMAIL PROTECTED]>
wrote:
Hi all,
How do I replace the same value multiple times without repeating the
same variable name/value repeatedly?
for ex.
some = 'thing'
print '%s %s %s %s' % (some,some,some,some)
You can use named parameters, which moves the repetition to the format
string:
In [24]: print '%(some)s %(some)s %(some)s %(some)s' % (dict(some=some))
thing thing thing thing
With multiple values, a common trick is to pass vars() or locals() as
the dict, giving the format access to all defined variables:
In [27]: a=1
In [28]: b=2
In [29]: print '%(a)s %(b)s' % vars()
1 2
If you literally need to repeat as in your example, you could do this:
In [26]: print '%s %s %s %s' % (4*(some,))
thing thing thing thing
Kent
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.python.org/pipermail/tutor/attachments/20080521/4ac3ef9d/attachment-0001.htm>
------------------------------
Message: 5
Date: Wed, 21 May 2008 08:45:10 -0400
From: "Kent Johnson" <[EMAIL PROTECTED]>
Subject: Re: [Tutor] python investment scheme assistance
To: "Binish Huma Qadir" <[EMAIL PROTECTED]>
Cc: tutor@python.org
Message-ID:
<[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1
On Wed, May 21, 2008 at 5:35 AM, Binish Huma Qadir
<[EMAIL PROTECTED]> wrote:
Hi,
I'm doing a Investment implementation project where i need to use the
following data:
http://app.lms.unimelb.edu.au/bbcswebdav/courses/600151_2008_1/datasets/finance/asx_large.csv
I've been instructed to design an investment scheme in python.
The investment scheme i have chosen is based on investing in 3companies
with the highest dividend yield and lowest debt equity ratio.
This sounds like a homework problem; we try to avoid doing homework.
We will help you with specific questions.
Do you know how to read the file? Maybe you could start with a program
that just reads and prints the csv file. The csv module can help with
that. Then compute and print the measures you need; finally pick out
the top three.
Try to write some code and ask here when you have trouble.
Kent
------------------------------
Message: 6
Date: Wed, 21 May 2008 16:42:11 +0300
From: Kinuthia Muchane <[EMAIL PROTECTED]>
Subject: [Tutor] String Replacement Question
To: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
st = "String"
print "%s " %st*3
String String String
Does this help?
Kinuthia...
-----------------------------
Message: 6
Date: Wed, 21 May 2008 15:05:21 +0530
From: Faheem <[EMAIL PROTECTED]>
Subject: [Tutor] String Replacement question
To: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=US-ASCII
Hi all,
How do I replace the same value multiple times without repeating the
same variable name/value repeatedly?
for ex.
some = 'thing'
print '%s %s %s %s' % (some,some,some,some)
in this case, my question is how do i replace "% (some,some,some)" with
something more concise?
thanks in advance,
Faheem
------------------------------
Message: 7
Date: Wed, 21 May 2008 10:29:41 -0400
From: "Moishy Gluck" <[EMAIL PROTECTED]>
Subject: Re: [Tutor] String Replacement Question
To: tutor@python.org
Message-ID:
<[EMAIL PROTECTED]>
Content-Type: text/plain; charset="iso-8859-1"
On Wed, May 21, 2008 at 10:29 AM, Moishy Gluck <[EMAIL PROTECTED]>
wrote:
"%s " %st*3
'String String String '
^
If you look closely at the end of the string there is an extra space.
" ".join((st, )*3)
'String String String'
^
No extra space.
On Wed, May 21, 2008 at 9:42 AM, Kinuthia Muchane <[EMAIL PROTECTED]>
wrote:
st = "String"
print "%s " %st*3
String String String
Does this help?
Kinuthia...
-----------------------------
Message: 6
Date: Wed, 21 May 2008 15:05:21 +0530
From: Faheem <[EMAIL PROTECTED]>
Subject: [Tutor] String Replacement question
To: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=US-ASCII
Hi all,
How do I replace the same value multiple times without repeating the
same variable name/value repeatedly?
for ex.
some = 'thing'
print '%s %s %s %s' % (some,some,some,some)
in this case, my question is how do i replace "% (some,some,some)" with
something more concise?
thanks in advance,
Faheem
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.python.org/pipermail/tutor/attachments/20080521/c486b262/attachment.htm>
------------------------------
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
End of Tutor Digest, Vol 51, Issue 44
*************************************