davalend

Members
  • Content Count

    14
  • Joined

  • Last visited

Posts posted by davalend

  1. That sounds like a homework question, and you didn't even specify a language.

    I'll give you a hint, the obvious solution is to use two loops, one nested in the other. But if you know the length of the list before starting, you can do it with just one loop.

    Heh, on second thought you don't even need to know the length of the list.

    the language is python

  2. read = open('rules.txt', 'r')

    a = read.readlines()

    arr = []

    for ruleline in a:

    arr.append(ruleline.split()[1])

    print arr

    -----------------------------------

    ['5510/2']

    ['5510/2', '2490/1']

    ['5510/2', '2490/1', '4728/2']

    ['5510/2', '2490/1', '4728/2', '1940/1']

    ['5510/2', '2490/1', '4728/2', '1940/1', '1940/1']

    ['5510/2', '2490/1', '4728/2', '1940/1', '1940/1', '5510/3']

    ---------------------------------------------------------------

    it keeps repeating. how come?

  3. read = open('sample.txt', 'r')

    a = read.readlines()

    arr = []

    for ruleline in a:

    for ruledata in ruleline[2:9]:

    arr.append(ruledata)

    print arr,

    what is wrong with this code? it prints ['5'] ['5', '5'] ['5', '5', '1'] ['5', '5', '1', '0'] ['5', '5', '1', '0', '/'] ['5', '5', '1', '0', '/', '2'] ['5', '5', '1', '0', '/', '2', ' '] .....

    what I want is 5510/2, not seperating them...

    pls guide me.

  4. this is my python code

    ----------------------------------

    read = open('sample.txt', 'r')

    a = read.readlines()

    for line in a :

    print line,

    ------------------------------------

    the above code will print all the line in the file. but if i wan it to print only certain % of the line(for example: 50% of the line). how do i code it?