[Hampshire] Python sorting

2012-09-01 Thread Leo
If I have a dictionary in Python, where the keys are strings, and the 
values are instances of a class of mine, how can I get the list of keys 
sorted based on a property on my class? I can obviously do this 
manually, but was wondering if there was an inbuilt Python way of doing 
it more easily. As an example:


Class MyClass:
def __init__(self, prop)
self.prop = prop

def main():
test=dict()
test["a"] = MyClass(46)
test["b"] = MyClass(3)
test["c"] = MyClass(15)

# I would like to generate
sortedTest=list()
#containing b, c, a in that order.

Thanks,
Leo


--
Please post to: Hampshire@mailman.lug.org.uk
Web Interface: https://mailman.lug.org.uk/mailman/listinfo/hampshire
LUG URL: http://www.hantslug.org.uk
--


Re: [Hampshire] Python sorting

2012-09-01 Thread Robin Wilson
Hi Leo,

You can do this fairly easily using the 'key' keyword argument for the 'sorted' 
function. Sorting a normal list can be done easily as:

s = sorted(test)

But if you want to tell it how to generate the value to sort on, you can use 
the key keyword, for example:

s = sorted(test, key=str.lower)

As you can see, the key parameter gives a function to be called on each of the 
elements before comparing them. In that case it uses a built-in Python function 
to convert each element to lowercase, but you can write your own function very 
easily to do what you want. You can do this by writing a normal function, like:

def f(value):
return value.prop

and then calling it as follows:

s = sorted(test.itervalues(), key=f)

or by writing a lambda function, which is basically the same, but inline and 
without a name:

s = sorted(test.itervalues(), key=lambda x: x.prop)

I'm using test.itervalues() as the list to use here as that will just provide a 
list of the values in the dictionary, not the keys.

Hope that helps,

Cheers,

Robin

On 1 Sep 2012, at 15:53, Leo  wrote:

> If I have a dictionary in Python, where the keys are strings, and the values 
> are instances of a class of mine, how can I get the list of keys sorted based 
> on a property on my class? I can obviously do this manually, but was 
> wondering if there was an inbuilt Python way of doing it more easily. As an 
> example:
> 
> Class MyClass:
>   def __init__(self, prop)
>   self.prop = prop
> 
> def main():
>   test=dict()
>   test["a"] = MyClass(46)
>   test["b"] = MyClass(3)
>   test["c"] = MyClass(15)
> 
>   # I would like to generate
>   sortedTest=list()
>   #containing b, c, a in that order.
> 
> Thanks,
> Leo
>   
> 
> --
> Please post to: Hampshire@mailman.lug.org.uk
> Web Interface: https://mailman.lug.org.uk/mailman/listinfo/hampshire
> LUG URL: http://www.hantslug.org.uk
> --


--
Please post to: Hampshire@mailman.lug.org.uk
Web Interface: https://mailman.lug.org.uk/mailman/listinfo/hampshire
LUG URL: http://www.hantslug.org.uk
--


Re: [Hampshire] RDP from Debian to Windows 7 with dual monitors?

2012-09-01 Thread Imran Chaudhry
>
>
> Thanks for that Peter, I have installed VNC and will give it a try
> tonight. I have the free version but thats OK as I am using the VPN to
> handle encryption and basic password is fine as long as it's strong.
>

Just wanted to follow-up: VNC is the best solution so far. I get to see
both desktops on the two remote monitors side-by-side on one large
rectangle, where I can use a scrollbar to view the entire width. I enabled
"scrolled window mode" and "grab all keyboard events" for best reulsts
(otherwise ctrl-alt-delete to unlock Windows produces the "shutdown" dialog
in Debian). I used Remmina to make the connection. RealVNC have a Linux
client but not sure if that will give me any advantage.

It's just shy of perfect though: I can also start another concurrent
session and my thought was to have each session viewing each desktop.
However in the second session, I can't interact with the remote side, the
mouse pointer is "stuck" as a double-ended arrow.

-- 
GPG Key fingerprint = B323 477E F6AB 4181 9C65  F637 BC5F 7FCC 9CC9 CC7F
http://about.me/imranchaudhry
--
Please post to: Hampshire@mailman.lug.org.uk
Web Interface: https://mailman.lug.org.uk/mailman/listinfo/hampshire
LUG URL: http://www.hantslug.org.uk
--

[Hampshire] [JOB] Support Developer (Jobsite, Havant)

2012-09-01 Thread Imran Chaudhry
Come and join an online giant in the arena of digital recruitment!

Jobsite (now called Evenbase) are looking for a Support Developer. You will
be part of a small team making sure the Jobsite family of websites is
maintained and running "business-as-usual". There are varied and
interesting analysis and challenges involved. We use the renowned FogBugz
case management tool and every developer has a powerful desktop with
dual-widescreen monitors so we have excellent tools (we also have UltraEdit
licences but you can use what you are most comfortable with). The desktop
is Windows 7 and an Exchange environment but you can elect to use any
flavour of Linux as long as you can self-admin. The team is part of a wider
IT group of about 20 developers.

Examples of some of the websites:
http://www.jobsite.co.uk/
http://www.justengineers.net/
http://www.thisisderbyshire.co.uk/jobs

We're mainly looking for someone with Perl but if you're proficient with
another popular Web-language and can self-teach yourself Perl then we still
want to hear from you. You need to have a good grasp of the elements of a
modern website eg. templates, JavaScript/HTML/CSS, databases and SQL. You
also need to have at least basic knowledge of the Linux command line, shell
scripts and utilities like grep.

This role not only calls upon good analysis and technical skills - you need
to have a good "human" approach as you will be interacting with users and
other developers. Good written and verbal English is essential. Having an
appreciation of typical business functions and what goes on in them is also
a plus.

The offices are situated in Langstone Technology Park in Havant (about 5
miles east of Portsmouth). The facilities are excellent with a huge car
park, on-site gym, coffee shop, resteraunt serving breakfast and lunch,
free wi-fi, rest-area and even a table-tennis table. There is a large Tesco
superstore nearby and Havant town centre has all the usual amenities. It's
easily commutable by car being just off the M27/A27. Havant rail station is
about 15 minutes walk. It is close to the coast and beautiful woodlands and
there are ample lunchtime walks available. The company also allows working
from home on occasion and we have a VPN access to workstations.

If all that sounds like something that motivates you then please contact me
direct if you are interested, thank you.

(I am only interested in hearing from potential applicants, no agents
please.)

-- 
GPG Key fingerprint = B323 477E F6AB 4181 9C65  F637 BC5F 7FCC 9CC9 CC7F
http://about.me/imranchaudhry
--
Please post to: Hampshire@mailman.lug.org.uk
Web Interface: https://mailman.lug.org.uk/mailman/listinfo/hampshire
LUG URL: http://www.hantslug.org.uk
--

[Hampshire] Surrey LUG Bring-a-box meeting: 8th September 2012, Sirius Corporation (Addlestone)

2012-09-01 Thread Robert Longstaff
Hello. I am a little late with this but still in time! - the next Surrey 
LUG Bring-a-box meeting is scheduled for Saturday 8th September at the 
Sirius Corporation offices in Addlestone, from 11am to 5pm.


(Note that the locations for September and October swapped - the meeting 
at RedHat in Farnborough will be in October.)


There is a dedicated page for this month, where you can add details of 
talks, presentations, etc.:


http://surrey.lug.org.uk/content/bab-september-2012

All offers of talks are gratefully received. It's often a good idea to 
put forward an idea of either a talk you can do or a subject you'd like 
to hear about on the mailing list or maybe even in the irc channel.


Details of how to get there are at:

http://surrey.lug.org.uk/Meetings/BringABox/Addlestone

Do let the list know if you're going by car and able to offer lifts.

Our thanks to Andrew Wilkins for hosting us this month.

Look forward to seeing you there!

robert_

--
Please post to: Hampshire@mailman.lug.org.uk
Web Interface: https://mailman.lug.org.uk/mailman/listinfo/hampshire
LUG URL: http://www.hantslug.org.uk
--


Re: [Hampshire] [JOB] Support Developer (Jobsite, Havant)

2012-09-01 Thread Jacqui Caren

On 01/09/2012 17:21, Imran Chaudhry wrote:

Come and join an online giant in the arena of digital recruitment!


It would help if you provided an estimated salary range.


The offices are situated in Langstone Technology Park in Havant (about 5 miles 
east of Portsmouth). The facilities are excellent with a huge car park, on-site 
gym, coffee shop, resteraunt serving
breakfast and lunch, free wi-fi, rest-area and even a table-tennis table. There 
is a large Tesco superstore nearby and Havant town centre has all the usual 
amenities. It's easily commutable by car
being just off the M27/A27. Havant rail station is about 15 minutes walk. It is 
close to the coast and beautiful woodlands and there are ample lunchtime walks 
available. The company also allows
working from home on occasion and we have a VPN access to workstations.


Stil at the same place!
I spent some time "on site" some years ago and I can say that the jobsite 
locale, people and work environ
is a "good'un" :-)

Jacqui

--
Please post to: Hampshire@mailman.lug.org.uk
Web Interface: https://mailman.lug.org.uk/mailman/listinfo/hampshire
LUG URL: http://www.hantslug.org.uk
--


Re: [Hampshire] Python sorting

2012-09-01 Thread Leo


Brilliant, thank you. I hadn't realised that Python could do lambda 
expressions as well, that's a bonus.


Leo


On 01/09/12 16:10, Robin Wilson wrote:

Hi Leo,

You can do this fairly easily using the 'key' keyword argument for
the 'sorted' function. Sorting a normal list can be done easily as:

s = sorted(test)

But if you want to tell it how to generate the value to sort on, you
can use the key keyword, for example:

s = sorted(test, key=str.lower)

As you can see, the key parameter gives a function to be called on
each of the elements before comparing them. In that case it uses a
built-in Python function to convert each element to lowercase, but
you can write your own function very easily to do what you want. You
can do this by writing a normal function, like:

def f(value): return value.prop

and then calling it as follows:

s = sorted(test.itervalues(), key=f)

or by writing a lambda function, which is basically the same, but
inline and without a name:

s = sorted(test.itervalues(), key=lambda x: x.prop)

I'm using test.itervalues() as the list to use here as that will just
provide a list of the values in the dictionary, not the keys.

Hope that helps,

Cheers,

Robin

On 1 Sep 2012, at 15:53, Leo  wrote:


If I have a dictionary in Python, where the keys are strings, and
the values are instances of a class of mine, how can I get the list
of keys sorted based on a property on my class? I can obviously do
this manually, but was wondering if there was an inbuilt Python way
of doing it more easily. As an example:

Class MyClass: def __init__(self, prop) self.prop = prop

def main(): test=dict() test["a"] = MyClass(46) test["b"] =
MyClass(3) test["c"] = MyClass(15)

# I would like to generate sortedTest=list() #containing b, c, a in
that order.

Thanks, Leo

-- Please post to: Hampshire@mailman.lug.org.uk Web Interface:
https://mailman.lug.org.uk/mailman/listinfo/hampshire LUG URL:
http://www.hantslug.org.uk
--



-- Please post to: Hampshire@mailman.lug.org.uk Web Interface:
https://mailman.lug.org.uk/mailman/listinfo/hampshire LUG URL:
http://www.hantslug.org.uk
--




--
Please post to: Hampshire@mailman.lug.org.uk
Web Interface: https://mailman.lug.org.uk/mailman/listinfo/hampshire
LUG URL: http://www.hantslug.org.uk
--