Re: Problem with list.insert

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marc 'BlackJack' Rintsch

    Re: Problem with list.insert

    On Thu, 28 Aug 2008 09:13:00 -0700, SUBHABRATA wrote:
    import re
    def wordchecker1(n) :
    # INPUTTING STRING
    a1=raw_input("P RINT ONE ENGLISH SENTENCE FOR DICTIONARY CHECK:")
    #CONVERTING TO LOWER CASE
    a2=a1.lower()
    #CONVERTING INTO LIST
    a3=a2.split()
    #DICTIONARY
    a4=open("/python25/Changedict3.txt ","r") a5=a4.read()
    a6=a5.split()
    found=[]
    not_found=[]
    #SEARCHING DICTIONARY
    for x in a3:
    a7="\n"
    a8=a7+x
    if a8 in a5:
    a9=a5.index(a8)
    a10=a5[a9:]
    a11=re.search(" \xe0.*?\n",a10)
    a12=a11.group()
    a13=a12[:-1]
    found.append(a1 3)
    elif a8 not in a5:
    a14=x
    not_found.appen d(a14)
    else:
    print "Error"
    found.extend(no t_found)
    # THE OUTPUT
    print "OUTPUT STRING IS"
    a15=(' '.join(found))
    #THE OUTPUT STRING
    print a15
    # SPLITTING OUTPUT STRING IN WORDS
    a16=a15.split()
    #TAKING OUT THE WORD FROM OUTPUT STRING for word in a16:
    #MATCHING WITH GIVEN STRING
    a17=a2.find(wor d)
    if a17>-1:
    print "The word is found in the Source String"
    a18=a3.index(wo rd)
    a19=a3[a18]
    print a19
    #INSERTING IN THE LIST OF TARGET STRING
    a20=a16.insert( a18,a19)
    print a16
    a21=(" ".join(a16) )
    print a21
    a1, a2, a2, …, a20? You must be kidding. Please stop numbering names
    and use *meaningful* names instead!

    Could you describe them problem better, with sample inputs and expected
    outputs. There must be a better way that that unreadable mess above.

    Ciao,
    Marc 'BlackJack' Rintsch
  • SUBHABRATA

    #2
    Re: Problem with list.insert

    Some people in the room told I am kidding, but I learnt Python from
    Python docs which gives examples like these,
    But I write explicit comments,
    an excerpt from python docs:
    # Measure some strings:
    .... a = ['cat', 'window', 'defenestrate']
    >>for x in a:
    .... print x, len(x)
    ....
    cat 3
    window 6
    defenestrate 12
    But well, if you are suggesting improvement I'll surely listen.

    The outputs are given in Hindi, it is a dictionary look up program,
    the matching words are in Hindi, you may leave aside them.
    How to debug the result string is to see the words which are in
    English as the group page does not take italics so I am putting one
    asterisk* after it
    NO PROBLEM:
    INPUT:
    he has come
    OUTPUT IS
    उओह/ उन्हो ने रहेसा क्ता २.यातॠà¤°à¤¾à¤•रठ¨à¤¾
    PROBLEM:
    INPUT:
    (i) Lincoln* has come
    OUTPUT IS:
    रहेसा क्ता २.यातॠà¤°à¤¾à¤•रठ¨à¤¾ lincoln*
    lincoln lincoln* रहेसा क्ता २.यातॠà¤°à¤¾à¤•रठ¨à¤¾ lincoln
    lincoln lincoln* lincoln* रहेसा क्ता २.यातॠà¤°à¤¾à¤•रठ¨à¤¾ lincoln
    ….and increasing the number and seems a never ending process.
    MY EXPEPECTED STRING IS:
    lincoln रहेसा क्ता २.यातॠà¤°à¤¾à¤•रठ¨à¤¾ lincoln^
    The latter places marked^ I am editing don't worry for that,
    though MY FINAL EXPECTED STRING IS:
    lincoln रहेसा क्ता २.यातॠà¤°à¤¾à¤•रठ¨à¤¾
    Best Regards,
    Subhabrata.



    Marc 'BlackJack' Rintsch wrote:
    On Thu, 28 Aug 2008 09:13:00 -0700, SUBHABRATA wrote:
    >
    import re
    def wordchecker1(n) :
    # INPUTTING STRING
    a1=raw_input("P RINT ONE ENGLISH SENTENCE FOR DICTIONARY CHECK:")
    #CONVERTING TO LOWER CASE
    a2=a1.lower()
    #CONVERTING INTO LIST
    a3=a2.split()
    #DICTIONARY
    a4=open("/python25/Changedict3.txt ","r") a5=a4.read()
    a6=a5.split()
    found=[]
    not_found=[]
    #SEARCHING DICTIONARY
    for x in a3:
    a7="\n"
    a8=a7+x
    if a8 in a5:
    a9=a5.index(a8)
    a10=a5[a9:]
    a11=re.search(" \xe0.*?\n",a10)
    a12=a11.group()
    a13=a12[:-1]
    found.append(a1 3)
    elif a8 not in a5:
    a14=x
    not_found.appen d(a14)
    else:
    print "Error"
    found.extend(no t_found)
    # THE OUTPUT
    print "OUTPUT STRING IS"
    a15=(' '.join(found))
    #THE OUTPUT STRING
    print a15
    # SPLITTING OUTPUT STRING IN WORDS
    a16=a15.split()
    #TAKING OUT THE WORD FROM OUTPUT STRING for word in a16:
    #MATCHING WITH GIVEN STRING
    a17=a2.find(wor d)
    if a17>-1:
    print "The word is found in the Source String"
    a18=a3.index(wo rd)
    a19=a3[a18]
    print a19
    #INSERTING IN THE LIST OF TARGET STRING
    a20=a16.insert( a18,a19)
    print a16
    a21=(" ".join(a16) )
    print a21
    >
    a1, a2, a2, …, a20? You must be kidding. Please stop numbering names
    and use *meaningful* names instead!
    >
    Could you describe them problem better, with sample inputs and expected
    outputs. There must be a better way that that unreadable mess above.
    >
    Ciao,
    Marc 'BlackJack' Rintsch

    Comment

    • Diez B. Roggisch

      #3
      Re: Problem with list.insert

      SUBHABRATA schrieb:
      Some people in the room told I am kidding, but I learnt Python from
      Python docs which gives examples like these,
      But I write explicit comments,
      an excerpt from python docs:
      # Measure some strings:
      ... a = ['cat', 'window', 'defenestrate']
      >>>for x in a:
      ... print x, len(x)
      ...
      cat 3
      window 6
      defenestrate 12
      But well, if you are suggesting improvement I'll surely listen.
      Please! Just because a tiny 3 lines example involing just *one* list
      doesn't give that a long & speaking name does not mean
      The outputs are given in Hindi, it is a dictionary look up program,
      the matching words are in Hindi, you may leave aside them.
      How to debug the result string is to see the words which are in
      English as the group page does not take italics so I am putting one
      asterisk* after it
      NO PROBLEM:
      INPUT:
      he has come
      OUTPUT IS
      उओह/ उन्हो ने रहेसा क्ता २.यातॠà¤°à¤¾à¤•रठ¨à¤¾
      PROBLEM:
      INPUT:
      (i) Lincoln* has come
      OUTPUT IS:
      रहेसा क्ता २.यातॠà¤°à¤¾à¤•रठ¨à¤¾ lincoln*
      lincoln lincoln* रहेसा क्ता २.यातॠà¤°à¤¾à¤•रठ¨à¤¾ lincoln
      lincoln lincoln* lincoln* रहेसा क्ता २.यातॠà¤°à¤¾à¤•रठ¨à¤¾ lincoln
      ….and increasing the number and seems a never ending process.
      MY EXPEPECTED STRING IS:
      lincoln रहेसा क्ता २.यातॠà¤°à¤¾à¤•रठ¨à¤¾ lincoln^
      The latter places marked^ I am editing don't worry for that,
      though MY FINAL EXPECTED STRING IS:
      lincoln रहेसा क्ता २.यातॠà¤°à¤¾à¤•रठ¨à¤¾
      Best Regards,
      Subhabrata.
      >
      >
      >
      Marc 'BlackJack' Rintsch wrote:
      >On Thu, 28 Aug 2008 09:13:00 -0700, SUBHABRATA wrote:
      >>
      >>import re
      >>def wordchecker1(n) :
      >> # INPUTTING STRING
      >> a1=raw_input("P RINT ONE ENGLISH SENTENCE FOR DICTIONARY CHECK:")
      >> #CONVERTING TO LOWER CASE
      >> a2=a1.lower()
      >> #CONVERTING INTO LIST
      >> a3=a2.split()
      >> #DICTIONARY
      >> a4=open("/python25/Changedict3.txt ","r") a5=a4.read()
      >> a6=a5.split()
      >> found=[]
      >> not_found=[]
      >> #SEARCHING DICTIONARY
      >> for x in a3:
      >> a7="\n"
      >> a8=a7+x
      >> if a8 in a5:
      >> a9=a5.index(a8)
      >> a10=a5[a9:]
      >> a11=re.search(" \xe0.*?\n",a10)
      >> a12=a11.group()
      >> a13=a12[:-1]
      >> found.append(a1 3)
      >> elif a8 not in a5:
      >> a14=x
      >> not_found.appen d(a14)
      >> else:
      >> print "Error"
      >> found.extend(no t_found)
      >> # THE OUTPUT
      >> print "OUTPUT STRING IS"
      >> a15=(' '.join(found))
      >> #THE OUTPUT STRING
      >> print a15
      >> # SPLITTING OUTPUT STRING IN WORDS
      >> a16=a15.split()
      >> #TAKING OUT THE WORD FROM OUTPUT STRING for word in a16:
      >> #MATCHING WITH GIVEN STRING
      >> a17=a2.find(wor d)
      >> if a17>-1:
      >> print "The word is found in the Source String"
      >> a18=a3.index(wo rd)
      >> a19=a3[a18]
      >> print a19
      >> #INSERTING IN THE LIST OF TARGET STRING
      >> a20=a16.insert( a18,a19)
      >> print a16
      >> a21=(" ".join(a16) )
      >> print a21
      >a1, a2, a2, …, a20? You must be kidding. Please stop numbering names
      >and use *meaningful* names instead!
      >>
      >Could you describe them problem better, with sample inputs and expected
      >outputs. There must be a better way that that unreadable mess above.
      >>
      >Ciao,
      > Marc 'BlackJack' Rintsch

      Comment

      • Diez B. Roggisch

        #4
        Re: Problem with list.insert

        Diez B. Roggisch schrieb:
        SUBHABRATA schrieb:
        >Some people in the room told I am kidding, but I learnt Python from
        >Python docs which gives examples like these,
        >But I write explicit comments,
        >an excerpt from python docs:
        ># Measure some strings:
        >... a = ['cat', 'window', 'defenestrate']
        >>>>for x in a:
        >... print x, len(x)
        >...
        >cat 3
        >window 6
        >defenestrate 12
        >But well, if you are suggesting improvement I'll surely listen.
        >
        Please! Just because a tiny 3 lines example involing just *one* list
        doesn't give that a long & speaking name does not mean
        discard my last post - I accidentially pressed submit to early.

        Numbering variable names surely is *not* found in any python example.
        Short names, as the examples are clear & don't require more meaningful
        names occur, yes. But nowhere you will find 2-figure enumerations.

        Each book or tutorial about programming will teach you to use meaningful
        variables for your program.

        As far as your explanation goes: there is *nothing* to be understood
        from a bunch of questionmarks + sometimes "lincoln" spread in between is
        not really helping.

        This is most probably not your fault, as somehow the hindi get's twisted
        to the questionmarks - however, I suggest you provide an example where
        the hindi is replaced with english words (translations, or placeholders)
        - otherwise, you won't be understood, and can't be helped.

        Diez

        Comment

        Working...