<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Calling python experts in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/calling-python-experts/m-p/6742100#M497072</link>
    <description>&lt;P&gt;Just declare the variable 'global' within the function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;myvar = 0

def my func():
    global myvar
    myvar = 1&lt;/PRE&gt;&lt;P&gt;Normally I wouldn't recommend using globals though.&lt;/P&gt;</description>
    <pubDate>Thu, 07 May 2015 16:49:01 GMT</pubDate>
    <dc:creator>RJHall</dc:creator>
    <dc:date>2015-05-07T16:49:01Z</dc:date>
    <item>
      <title>Calling python experts</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/calling-python-experts/m-p/6740994#M497067</link>
      <description>&lt;P&gt;Hi Python experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I havent posted here for a while but I am hoping some good willed python expert can help with a list/sort problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a python input file with the following names/scores in;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;seb 99&lt;BR /&gt;seb 75&lt;BR /&gt;stefan 100&lt;BR /&gt;dominik 80&lt;BR /&gt;stefan 89&lt;BR /&gt;seb 66&lt;BR /&gt;dominik 90&lt;BR /&gt;mum 45&lt;BR /&gt;mojo 99&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to read this file into a list then sort by score (not name) and display names/scores. BUT if a name appears &amp;gt; 1 time (which is does) then only display the highest score for that name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Stefan&lt;/P&gt;&lt;P&gt;Unix Manager.&lt;/P&gt;&lt;P&gt;Colt Telecom&lt;/P&gt;&lt;P&gt;London&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 May 2015 10:25:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/calling-python-experts/m-p/6740994#M497067</guid>
      <dc:creator>Md_Shaahbuddin</dc:creator>
      <dc:date>2015-05-05T10:25:50Z</dc:date>
    </item>
    <item>
      <title>Re: Calling python experts</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/calling-python-experts/m-p/6741212#M497068</link>
      <description>&lt;P&gt;Well it's not a terribly sophisticated approach, but this seems to work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;from operator import itemgetter

data = [('seb', 99), ('seb', 75), ('stefan', 100),
        ('dominik', 80), ('stefan', 89), ('seb', 66),
        ('dominik', 90), ('mum', 45), ('mojo', 99) ]

data.sort( key=itemgetter(1), reverse=True )
data.sort( key=itemgetter(0) )
newdata = []
lastname = ''
for (name, value) in data&amp;amp;colon;
        if name != lastname:
                newdata.append( (name, value) )
        lastname = name
print newdata&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;The ampersand-colon-semicolon is supposed to be a colon, but the editor keeps changing it.&lt;/P&gt;</description>
      <pubDate>Tue, 05 May 2015 18:19:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/calling-python-experts/m-p/6741212#M497068</guid>
      <dc:creator>RJHall</dc:creator>
      <dc:date>2015-05-05T18:19:55Z</dc:date>
    </item>
    <item>
      <title>Re: Calling python experts</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/calling-python-experts/m-p/6741240#M497069</link>
      <description>&lt;P&gt;Thanks RJHall for the reply!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately my list looks different to yours.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my input file looks like this;&lt;/P&gt;&lt;P&gt;seb 99&lt;BR /&gt;seb 75&lt;BR /&gt;stefan 100&lt;BR /&gt;dominik 80&lt;BR /&gt;stefan 89&lt;BR /&gt;seb 66&lt;BR /&gt;dominik 90&lt;BR /&gt;mum 45&lt;BR /&gt;mojo 99&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I print my list it looks different to yours, mine looks like this;&lt;/P&gt;&lt;P&gt;['seb 99', 'seb 75', 'stefan 100', 'dominik 80', 'stefan 89', 'seb 66', 'dominik 90', 'mum 45', 'mojo 99']&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but your data list looks like this and so your code works;&lt;/P&gt;&lt;P&gt;[('seb', 99), ('seb', 75), ('stefan', 100), ('dominik', 80), ('stefan', 89), ('seb', 66), ('dominik', 90), ('mum', 45), ('mojo', 99)]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I read in my input file to a list like yours ?&lt;/P&gt;&lt;P&gt;or copy my list to one like yours ? then your code will work a treat.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again for your time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 May 2015 20:10:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/calling-python-experts/m-p/6741240#M497069</guid>
      <dc:creator>Md_Shaahbuddin</dc:creator>
      <dc:date>2015-05-05T20:10:59Z</dc:date>
    </item>
    <item>
      <title>Re: Calling python experts</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/calling-python-experts/m-p/6741260#M497070</link>
      <description>&lt;P&gt;Well, if you had your data in a file called 'data':&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;from operator import itemgetter

data = []
f = open('data', 'r')
for line in f:
        value = line.rstrip('\n').split(" ")
        data.append( ( value[0], value[1] ) )

data.sort( key=itemgetter(1), reverse=True )
data.sort( key=itemgetter(0) )
newdata = []
lastname = ''
for (name, value) in data&amp;amp;colon;
        if name != lastname:
                newdata.append( (name, value) )
        lastname = name

for (name, value) in newdata&amp;amp;colon;
        print "%s %s" % (name, value)&lt;/PRE&gt;&lt;P&gt;For a larger file, some way to combine the two sort steps would probably be more efficient.&lt;/P&gt;</description>
      <pubDate>Tue, 05 May 2015 21:38:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/calling-python-experts/m-p/6741260#M497070</guid>
      <dc:creator>RJHall</dc:creator>
      <dc:date>2015-05-05T21:38:18Z</dc:date>
    </item>
    <item>
      <title>Re: Calling python experts</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/calling-python-experts/m-p/6741270#M497071</link>
      <description>&lt;P&gt;thats fantastic, it works a treat. thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;one last question.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when we declare a variable right at the top of our code. eg;&lt;/P&gt;&lt;P&gt;counter = 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;later in a function even though we pass it with function(counter) it does not update the global variable. Each time we call our function its gone back to 0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;how do we change&amp;nbsp;our global variable in a function so that it stays permanently changed&amp;nbsp;when it returns to the main loop or we call other functions ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 May 2015 22:18:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/calling-python-experts/m-p/6741270#M497071</guid>
      <dc:creator>Md_Shaahbuddin</dc:creator>
      <dc:date>2015-05-05T22:18:54Z</dc:date>
    </item>
    <item>
      <title>Re: Calling python experts</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/calling-python-experts/m-p/6742100#M497072</link>
      <description>&lt;P&gt;Just declare the variable 'global' within the function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;myvar = 0

def my func():
    global myvar
    myvar = 1&lt;/PRE&gt;&lt;P&gt;Normally I wouldn't recommend using globals though.&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2015 16:49:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/calling-python-experts/m-p/6742100#M497072</guid>
      <dc:creator>RJHall</dc:creator>
      <dc:date>2015-05-07T16:49:01Z</dc:date>
    </item>
  </channel>
</rss>

