Re: [Tutor] Question on joining out of order dictionary elements

2007-01-11 Thread Luke Paireepinart
raghu raghu wrote:
>
> [snip original message]
>
>
> To print or to retain individual values from a list,it has to be 
> written in the form of
> config={'test1':'elem1','test2':'elem2','test3':'elem3'}
> config['test4'] = 'elem4'
> print config.values()
> print config['test1']- To get individual values from a list
> If we want to retrieve all the values or say 2 from 4 its not possible 
> to put in a while loop and get that as a list only takes one argument 
> at a time better way is to extract individually and respective keys 
> could not be obtained if corresponding values are given.
Hello, raghu -
Please don't reply like this.
It breaks threading.
You should have a Re: in the title bar,
and the quoted text should have > before it.
If you reply like you did, it creates a new thread in Thunderbird.
I believe the 'reply all' button has some kind of magic that tells mail 
clients it's a reply to another message.

In addition, please don't use bolding.
If you reply normally, it will be clear what text is yours and what is 
from the original author.
Bolding text just makes it harder to read.
Thanks,
-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question on joining out of order dictionary elements

2007-01-11 Thread Andrew Robert
I like this solution.

Thanks everyone for all of the suggestions.

On 1/11/07, Andre Engels <[EMAIL PROTECTED]> wrote:
> 2007/1/11, raghu raghu <[EMAIL PROTECTED]>:
>
> > >>> print "\\".join((config["val2"]
> > ,config["val1"],config["val3"]))
> > elem2\elem1\elem3
> >
> > or
> >
> > >>> print "%s\\%s\\%s" %
> (config["val2"],config["val1"],config["val3"])
> > elem2\elem1\elem3
> >
> > but this seems somehow uneligent.
> >
> > Are there a more efficient/compact ways of doing this kind of
> > operation or is this it?
> >
>
> Maybe you like:
> print "\\".join([config[val] for val in ["val2","val1","val3"]])
>
> --
> Andre Engels, [EMAIL PROTECTED]
> ICQ: 6260644  --  Skype: a_engels
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
>


-- 
Thank you,
Andrew Robert

Senior MQ Engineer
Information Technologies
Massachusetts Financial Services
Phone: 617-954-5882
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question on joining out of order dictionary elements

2007-01-11 Thread Andre Engels

2007/1/11, raghu raghu <[EMAIL PROTECTED]>:


>>> print "\\".join((config["val2"],config["val1"],config["val3"]))
elem2\elem1\elem3

or

>>> print "%s\\%s\\%s" % (config["val2"],config["val1"],config["val3"])
elem2\elem1\elem3

but this seems somehow uneligent.

Are there a more efficient/compact ways of doing this kind of
operation or is this it?



Maybe you like:
print "\\".join([config[val] for val in ["val2","val1","val3"]])

--
Andre Engels, [EMAIL PROTECTED]
ICQ: 6260644  --  Skype: a_engels
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Question on joining out of order dictionary elements

2007-01-11 Thread raghu raghu

Hi everyone,

I have a quick quick question joining out of order dictionary values.

For example:

I created an empty


config={}


Added some key/value pairs


config["test1"]="elem1"
config["test2"]="elem2"
config["test3"]="elem3"


etc




Dumped the values and joined them at the same time.


print "\\".join(config.values())

elem1\elem3\elem2

This is fine but it doesn't entirely solve the issue.

Only some of the key/value pairs in the dictionary are needed so a
dump of all values does not work.

Also, the order in which the values are joined is important so walking
through and joining all values does not work either.


The simplest way would be to do something like:


print "\\".join((config["val2"],config["val1"],config["val3"]))

elem2\elem1\elem3

or


print "%s\\%s\\%s" % (config["val2"],config["val1"],config["val3"])

elem2\elem1\elem3

but this seems somehow uneligent.

Are there a more efficient/compact ways of doing this kind of
operation or is this it?

The key/value pairs in these examples are contrived for purposes of
this discussion but the end goal is to piece together server and
directory path information for use with pysvn.

I have a Perl programmer who is learning Python and he is griping that
this kind of operation is far simpler in Perl.

To print or to retain individual values from a list,it has to be written in
the form of
config={'test1':'elem1','test2':'elem2','test3':'elem3'}
config['test4'] = 'elem4'
print config.values()
print config['test1']- To get individual values from a list
If we want to retrieve all the values or say 2 from 4 its not possible to
put in a while loop and get that as a list only takes one argument at a time
better way is to extract individually and respective keys could not be
obtained if corresponding values are given.



--

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


Re: [Tutor] Question on joining out of order dictionary elements

2007-01-10 Thread John Fouhy
On 11/01/07, Andrew Robert <[EMAIL PROTECTED]> wrote:
> Only some of the key/value pairs in the dictionary are needed so a
> dump of all values does not work.
>
> Also, the order in which the values are joined is important so walking
> through and joining all values does not work either.

Well, a dictionary is by definition unordered, so you will need to
tell python which elements you want, and in which order.

I would do something like this:


config = {}
# insert code here to set the values of config

keysToDump = ['test1', 'test2', 'test3']
output = '\\'.join(config[k] for k in keysToDump)


(note that, if you are using python2.3 or earlier, you will need to
write that last line as:

output = '\\'.join([config[k] for k in keysToDump])

)

HTH!

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


[Tutor] Question on joining out of order dictionary elements

2007-01-10 Thread Andrew Robert
Hi everyone,

I have a quick quick question joining out of order dictionary values.

For example:

I created an empty

>>> config={}

Added some key/value pairs

>>> config["test1"]="elem1"
>>> config["test2"]="elem2"
>>> config["test3"]="elem3"

  etc
>>>

Dumped the values and joined them at the same time.

>>> print "\\".join(config.values())
elem1\elem3\elem2

This is fine but it doesn't entirely solve the issue.

Only some of the key/value pairs in the dictionary are needed so a
dump of all values does not work.

Also, the order in which the values are joined is important so walking
through and joining all values does not work either.


The simplest way would be to do something like:

>>> print "\\".join((config["val2"],config["val1"],config["val3"]))
elem2\elem1\elem3

or

>>> print "%s\\%s\\%s" % (config["val2"],config["val1"],config["val3"])
elem2\elem1\elem3

but this seems somehow uneligent.

Are there a more efficient/compact ways of doing this kind of
operation or is this it?

The key/value pairs in these examples are contrived for purposes of
this discussion but the end goal is to piece together server and
directory path information for use with pysvn.

I have a Perl programmer who is learning Python and he is griping that
this kind of operation is far simpler in Perl.

-- 
Thank you,
Andrew Robert

Senior MQ Engineer
Information Technologies
Massachusetts Financial Services
Phone: 617-954-5882
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor