<div dir="ltr">Hi All ,<div><br></div><div>         I got few steps ahead :  How to I iterate from keys of one dictionary to another and just compare the version ?</div><div><br></div><div>

<pre style="white-space:pre-wrap;text-decoration-style:initial;text-decoration-color:initial;background-color:rgb(255,255,255);color:rgb(0,0,0);font-family:"Courier New";font-size:12pt"><span style="color:rgb(0,0,128);font-weight:bold">import </span>os<br><span style="color:rgb(0,0,128);font-weight:bold">import </span>re<br><span style="color:rgb(0,0,128);font-weight:bold">from </span>distutils.version <span style="color:rgb(0,0,128);font-weight:bold">import </span>StrictVersion<br><span style="color:rgb(0,0,128);font-weight:bold">import </span>operator<br><br>lines=[]<br>new_dict={}<br>old_dict={}<br><br><br>fo = <span style="color:rgb(0,0,128)">open</span>(<span style="color:rgb(0,128,0);font-weight:bold">"rpmlist1.txt"</span>, <span style="color:rgb(0,128,0);font-weight:bold">"r"</span>)<br><span style="color:rgb(0,0,128);font-weight:bold">for </span>line <span style="color:rgb(0,0,128);font-weight:bold">in </span>fo:<br>    line=line.strip()<br>    lines.append(line)<br><br><span style="color:rgb(128,128,128);font-style:italic">#print lines<br></span><span style="color:rgb(128,128,128);font-style:italic"><br></span>get_rpm_parts = re.compile(<span style="color:rgb(0,128,0);font-weight:bold">r"""<br></span><span style="color:rgb(0,128,0);font-weight:bold">      ^ (.*)        # name<br></span><span style="color:rgb(0,128,0);font-weight:bold">      - (.*)        # version<br></span><span style="color:rgb(0,128,0);font-weight:bold">      - ([0-9]+)    # build<br></span><span style="color:rgb(0,128,0);font-weight:bold">      [.] ([^.]+)   # os<br></span><span style="color:rgb(0,128,0);font-weight:bold">      [.] ([^.]+) $ # architecture<br></span><span style="color:rgb(0,128,0);font-weight:bold">"""</span>, re.X)<br><br><span style="color:rgb(0,0,128);font-weight:bold">for </span>s <span style="color:rgb(0,0,128);font-weight:bold">in </span>lines:<br>    match = re.search(get_rpm_parts, s)<br>    <span style="color:rgb(0,0,128);font-weight:bold">if </span>match :<br> <span style="color:rgb(128,128,128);font-style:italic">#       print "name: %s ver: %s arch: %s" % (match1.group ( 1 ), match1.group ( 2 ), match1.group ( 5 ))<br></span><span style="color:rgb(128,128,128);font-style:italic">        </span>new_dict[match.group(<span style="color:rgb(0,0,255)">1</span>)] = {<span style="color:rgb(0,128,0);font-weight:bold">"name"</span>: s, <span style="color:rgb(0,128,0);font-weight:bold">"version"</span>: match.group ( <span style="color:rgb(0,0,255)">2 </span>), <span style="color:rgb(0,128,0);font-weight:bold">"build"</span>: match.group ( <span style="color:rgb(0,0,255)">3 </span>),<span style="color:rgb(0,128,0);font-weight:bold">"os"</span>: match.group ( <span style="color:rgb(0,0,255)">4 </span>), <span style="color:rgb(0,128,0);font-weight:bold">"arch"</span>: match.group ( <span style="color:rgb(0,0,255)">5 </span>)}<br>        <span style="color:rgb(128,128,128);font-style:italic">#else:<br></span><span style="color:rgb(128,128,128);font-style:italic">     #   print "no match1",s<br></span><span style="color:rgb(128,128,128);font-style:italic"><br></span><span style="color:rgb(0,0,128);font-weight:bold">print </span>new_dict<br><br>list1 = [<br>        <span style="color:rgb(0,128,0);font-weight:bold">"binutils-2.23.52.0.1-12.el7.x86_64"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"compat-libcap1-1.10-3.el7.x86_64"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"compat-libstdc++-33-3.2.3-71.el7.i686"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"compat-libstdc++-33-3.2.3-71.el7.x86_64"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"gcc-4.8.2-3.el7.x86_64"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"gcc-c++-4.8.2-3.el7.x86_64"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"glibc-2.17-36.el7.i686"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"glibc-2.17-36.el7.x86_64"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"glibc-devel-2.17-36.el7.i686"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"glibc-devel-2.17-36.el7.x86_64"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"ksh"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"libaio-0.3.109-9.el7.i686"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"libaio-0.3.109-9.el7.x86_64"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"libaio-devel-0.3.109-9.el7.i686"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"libaio-devel-0.3.109-9.el7.x86_64"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"libgcc-4.8.2-3.el7.i686"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"libgcc-4.8.2-3.el7.x86_64"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"libstdc++-4.8.2-3.el7.i686"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"libstdc++-4.8.2-3.el7.x86_64"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"libstdc++-devel-4.8.2-3.el7.i686"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"libstdc++-devel-4.8.2-3.el7.x86_64"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"libXi-1.7.2-1.el7.i686"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"libXi-1.7.2-1.el7.x86_64"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"libXtst-1.2.2-1.el7.i686"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"libXtst-1.2.2-1.el7.x86_64"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"make-3.82-19.el7.x86_64"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"sysstat-10.1.5-1.el7.x86_64"</span>,<br>]<br><br><span style="color:rgb(0,0,128);font-weight:bold">for </span>i <span style="color:rgb(0,0,128);font-weight:bold">in </span>list1:<br>    match1 = re.search(get_rpm_parts, i)<br>    <span style="color:rgb(0,0,128);font-weight:bold">if </span>match1:<br>        <span style="color:rgb(128,128,128);font-style:italic">#print "name: %s ver: %s arch: %s" % (match1.group ( 1 ), match1.group ( 2 ), match1.group ( 5 ))<br></span><span style="color:rgb(128,128,128);font-style:italic">        </span>old_dict[match1.group ( <span style="color:rgb(0,0,255)">1 </span>)] = {<span style="color:rgb(0,128,0);font-weight:bold">"name"</span>: i, <span style="color:rgb(0,128,0);font-weight:bold">"version"</span>: match1.group ( <span style="color:rgb(0,0,255)">2 </span>), <span style="color:rgb(0,128,0);font-weight:bold">"build"</span>: match1.group ( <span style="color:rgb(0,0,255)">3 </span>),<span style="color:rgb(0,128,0);font-weight:bold">"os"</span>: match1.group ( <span style="color:rgb(0,0,255)">4 </span>), <span style="color:rgb(0,128,0);font-weight:bold">"arch"</span>: match1.group ( <span style="color:rgb(0,0,255)">5 </span>)}<br>    <span style="color:rgb(128,128,128);font-style:italic"># else:<br></span><span style="color:rgb(128,128,128);font-style:italic">    #   print "no match1",s<br></span><span style="color:rgb(128,128,128);font-style:italic"><br></span><span style="color:rgb(0,0,128);font-weight:bold">print </span>old_dict<br></pre><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">----Please let me know from here how to proceed further</span>   ***************<br></div></div><br><div class="gmail_quote"><div dir="ltr">On Sat, Jul 28, 2018 at 1:20 PM Nathan Jeffrey <<a href="mailto:nathan.jeffrey@gmail.com">nathan.jeffrey@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto">If I were going to do that, I would make those lists into sets, and then you could use set arithmetic to calculate the intersections.<div dir="auto"><br></div><div dir="auto">Have a look on Stack Overflow. This is fairly bread-and-butter stuff, and I am sure there is a better answer there than I could concoct here 😁</div><div dir="auto"><br></div><div dir="auto">Good luck!</div><div dir="auto"><br></div><div dir="auto">- N</div></div><br><div class="gmail_quote"><div dir="ltr">On Sat, 28 Jul 2018, 08:42 Asad, <<a href="mailto:asad.hasan2004@gmail.com" target="_blank">asad.hasan2004@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi All ,<div><br></div><div>           I am new to python just completed 4 lecture on python, I am  looking for a pyhton script of module which check the versions of the rpm in linux .</div><div><br></div><div>          I have a situation in which I have two list list1 and list2 :</div><div><br></div><div>list1 is prerequisites rpm for application</div><div><br></div><div>and list2 is the list of rpm's in the system           <pre style="background-color:rgb(255,255,255);color:rgb(0,0,0);font-family:"Courier New";font-size:12pt">list1 = [<br>        <span style="color:rgb(0,128,0);font-weight:bold">"binutils-2.23.52.0.1-12.el7.x86_64"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"compat-libcap1-1.10-3.el7.x86_64"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"compat-libstdc++-33-3.2.3-71.el7.i686"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"compat-libstdc++-33-3.2.3-71.el7.x86_64"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"gcc-4.8.2-3.el7.x86_64"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"gcc-c++-4.8.2-3.el7.x86_64"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"glibc-2.17-36.el7.i686"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"glibc-2.17-36.el7.x86_64"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"glibc-devel-2.17-36.el7.i686"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"glibc-devel-2.17-36.el7.x86_64"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"ksh"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"libaio-0.3.109-9.el7.i686"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"libaio-0.3.109-9.el7.x86_64"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"libaio-devel-0.3.109-9.el7.i686"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"libaio-devel-0.3.109-9.el7.x86_64"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"libgcc-4.8.2-3.el7.i686"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"libgcc-4.8.2-3.el7.x86_64"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"libstdc++-4.8.2-3.el7.i686"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"libstdc++-4.8.2-3.el7.x86_64"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"libstdc++-devel-4.8.2-3.el7.i686"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"libstdc++-devel-4.8.2-3.el7.x86_64"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"libXi-1.7.2-1.el7.i686"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"libXi-1.7.2-1.el7.x86_64"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"libXtst-1.2.2-1.el7.i686"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"libXtst-1.2.2-1.el7.x86_64"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"make-3.82-19.el7.x86_64"</span>,<br>        <span style="color:rgb(0,128,0);font-weight:bold">"sysstat-10.1.5-1.el7.x86_64"</span>,<br>]</pre><div>lsit2 = ['acl-2.2.51-12.el7.x86_64', 'adcli-0.8.1-3.el7.x86_64', 'audit-2.7.6-3.el7.x86_64', 'audit-libs-2.7.6-3.el7.i686', 'audit-libs-2.7.6-3.el7.x86_64', 'audit-libs-python-2.7.6-3.el7.x86_64', 'authconfig-6.2.8-30.el7.x86_64', 'autofs-5.0.7-70.0.1.el7_4.1.x86_64', 'autogen-libopts-5.18-5.el7.x86_64', 'avahi-autoipd-0.6.31-17.el7.x86_64', 'avahi-libs-0.6.31-17.el7.x86_64', 'bash-4.2.46-29.el7_4.x86_64', 'bc-1.06.95-13.el7.x86_64', 'bind-libs-9.9.4-51.el7_4.2.x86_64', 'bind-libs-lite-9.9.4-51.el7_4.2.x86_64', 'bind-license-9.9.4-51.el7_4.2.noarch', 'bind-utils-9.9.4-51.el7_4.2.x86_64', 'binutils-2.25.1-32.base.el7_4.2.x86_64', 'biosdevname-0.7.2-2.el7.x86_64', 'btrfs-progs-4.9.1-1.0.2.el7.x86_64', 'bzip2-1.0.6-13.el7.x86_64', 'bzip2-libs-1.0.6-13.el7.i686', 'bzip2-libs-1.0.6-13.el7.x86_64', 'ca-certificates-2017.2.14-71.el7.noarch', 'c-ares-1.10.0-3.el7.x86_64', 'checkpolicy-2.5-4.el7.x86_64', 'chkconfig-1.7.4-1.el7.x86_64', 'compat-libcap1-1.10-7.el7.x86_64', 'compat-libstdc++-33-3.2.3-72.el7.i686', 'compat-libstdc++-33-3.2.3-72.el7.x86_64', 'coreutils-8.22-18.0.1.el7.x86_64', 'cpio-2.11-25.el7_4.x86_64', 'cpp-4.8.5-16.0.3.el7_4.2.x86_64', 'cracklib-2.9.0-11.el7.i686', 'cracklib-2.9.0-11.el7.x86_64', 'cracklib-dicts-2.9.0-11.el7.x86_64', 'cronie-1.4.11-17.el7.x86_64', 'cronie-anacron-1.4.11-17.el7.x86_64']</div></div><div><br></div><div>I would like to do a rpm version check between the two list  (list1 and list2)</div><div><br></div><div>so it only prints the rpm from list1 which are not installed and version available in list2 is higher or lower .</div><div><br></div><div> Thanks in advance ,</div><div><br></div><br><div class="gmail_quote"><div dir="ltr">On Sat, Jul 28, 2018 at 1:31 AM <<a href="mailto:python-uk-request@python.org" rel="noreferrer" target="_blank">python-uk-request@python.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Welcome to the <a href="mailto:python-uk@python.org" rel="noreferrer" target="_blank">python-uk@python.org</a> mailing list! Welcome to the<br>
python-uk mailing list.<br>
<br>
This list is to help UK Python users to form a community, arrange<br>
events, advertise help or jobs wanted or sought and generally chat.<br>
<br>
<br>
To post to this list, send your message to:<br>
<br>
  <a href="mailto:python-uk@python.org" rel="noreferrer" target="_blank">python-uk@python.org</a><br>
<br>
General information about the mailing list is at:<br>
<br>
  <a href="https://mail.python.org/mailman/listinfo/python-uk" rel="noreferrer noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-uk</a><br>
<br>
If you ever want to unsubscribe or change your options (eg, switch to<br>
or from digest mode, change your password, etc.), visit your<br>
subscription page at:<br>
<br>
  <a href="https://mail.python.org/mailman/options/python-uk/asad.hasan2004%40gmail.com" rel="noreferrer noreferrer" target="_blank">https://mail.python.org/mailman/options/python-uk/asad.hasan2004%40gmail.com</a><br>
<br>
<br>
You can also make such adjustments via email by sending a message to:<br>
<br>
  <a href="mailto:python-uk-request@python.org" rel="noreferrer" target="_blank">python-uk-request@python.org</a><br>
<br>
with the word `help' in the subject or body (don't include the<br>
quotes), and you will get back a message with instructions.<br>
<br>
You must know your password to change your options (including changing<br>
the password, itself) or to unsubscribe without confirmation.  It is:<br>
<br>
  Welc0me@1<br>
<br>
Normally, Mailman will remind you of your <a href="http://python.org" rel="noreferrer noreferrer" target="_blank">python.org</a> mailing list<br>
passwords once every month, although you can disable this if you<br>
prefer.  This reminder will also include instructions on how to<br>
unsubscribe or change your account options.  There is also a button on<br>
your options page that will email your current password to you.<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="m_6646915632307705062m_8962953596527581120gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Asad Hasan<br>+91 9582111698</div></div></div>
_______________________________________________<br>
python-uk mailing list<br>
<a href="mailto:python-uk@python.org" rel="noreferrer" target="_blank">python-uk@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-uk" rel="noreferrer noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-uk</a><br>
</blockquote></div>
_______________________________________________<br>
python-uk mailing list<br>
<a href="mailto:python-uk@python.org" target="_blank">python-uk@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-uk" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-uk</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Asad Hasan<br>+91 9582111698</div></div>