Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Search results

  1. hanginthere

    Python Write in lines from a txt that is called by the occurrence of two strings

    Personally I prefer clear over clever. """ Displays all lines between 'input' and 'optimized' only if the number of lines is two. """ collect = False for line in open('input.txt'): line = line.replace('\n','') if line == 'input': collect = True lines = [] elif...
  2. hanginthere

    Python Write in lines from a txt that is called by the occurrence of two strings

    Look at it this way. If you see a line that is 'input' you want to start collecting lines. If you see a line that is 'optimized' you want to stop collecting lines, and if the number of collected lines is two you want to print them out. All you need to add is some housekeeping to set/clear a...
  3. hanginthere

    Python Request for an exercise from homework

    I'm a little late to the game but I thought I'd add a slightly different approach. A simple mathematical calculation can reduce each number to a group number, which can then be used to aggregate the individual numbers into a list. Here's the code. """ Take a string of a list of comma separated...
  4. hanginthere

    Python Doubt about recursion

    I just want to add a note about recursion. It's a good technique for certain things but is very bad in some cases. Whenever you call a function the system must make a note of where to return when the call is done. Typically it keeps this (and other information) on a stack. In the case of...
  5. hanginthere

    Python Longest substring in a string

    I find it helpful to work through an example by hand. Write your string on a piece of paper. Make two columns and call one sub (for substring) and the other one longest (for longest substring). Start by writing the first letter under sub. As you step through the letters, if the next letter is >=...
  6. hanginthere

    Greetings

    I am a retired (since 2008) computer programmer who learned the art/science way back in the stone age when punch cards and paper tape were still being used in production. I have programmed in FORTRAN, APL, PL/I, COBOL, SQL, Paradox, vb.NET, Python, C and C++, and dabbled in a few others like...
  7. hanginthere

    Python Problem with split() and rstrip()

    import requests # Get the page text = requests.get("https://www.py4e.com/code3/mbox-short.txt").text #sender is a dictionary where # key = address of sender # val = number of messages from this sender sender = {} for line in text.split('\n'): if line.startswith('From')...
Back
Top Bottom