Search Results

Search found 2 results on 1 pages for 'marks34'.

Page 1/1 | 1 

  • Create form select from object containing values

    - by marks34
    I have such an object : var options = {1: 'Running', 2: 'Falling', 3: 'Collapsing wall', 4: (...)}; I'd like to create form's select element with ooptions taken from this object, so something like that (code I tried which is not working, but you can get the idea) : html = '<form action="" ><select name="block-action"><option>-------</option>'; for(k in obj){ html += '<option value="'+k+'">'+obj[k]+'</option>' } html += '</select></form>'

    Read the article

  • How to optimize this script

    - by marks34
    I have written the following script. It opens a file, reads each line from it splitting by new line character and deleting first character in line. If line exists it's being added to array. Next each element of array is splitted by whitespace, sorted alphabetically and joined again. Every line is printed because script is fired from console and writes everything to file using standard output. I'd like to optimize this code to be more pythonic. Any ideas ? import sys def main(): filename = sys.argv[1] file = open(filename) arr = [] for line in file: line = line[1:].replace("\n", "") if line: arr.append(line) for line in arr: lines = line.split(" ") lines.sort(key=str.lower) line = ''.join(lines) print line if __name__ == '__main__': main()

    Read the article

1