Hey there! Sign in to join this conversationNew here? Join for free
    • Thread Starter
    Offline

    0
    ReputationRep:
    i have been set a task which says,
    "Develop a program that identifies individual words in a sentence, stores these in a list and replaces each word in the original sentence with the position of that word in the list.For example, the sentence ASK NOT WHAT YOUR COUNTRY CAN DO FOR YOU ASK WHAT YOU CAN DO FOR YOUR COUNTRYcontains the words ASK, NOT, WHAT, YOUR, COUNTRY, CAN, DO, FOR, YOUThe sentence can be recreated from the positions of these words in this list using the sequence1,2,3,4,5,6,7,8,9,1,3,9, 6,7,8,4,5Save the list of words and the positions of these words in the sentence as separate files or as a single file.
    Analyse the requirements for this system and design, develop, test and evaluate a program to:
    • identify the individual words in a sentence and store them in a list
    • create a list of positions for words in that list
    • save these lists as a single file or as separate files."
    can someone tell me how to do this in python 2.7.10
    Offline

    11
    ReputationRep:
    You might want to start with the following code:

    string = "ASK NOT WHAT YOUR COUNTRY CAN DO FOR YOU ASK WHAT YOU CAN DO FOR YOUR COUNTRY"
    stringWords = string.split()
    Offline

    10
    ReputationRep:
    hi

    i'm doing a similar task too
    try looking into codes for like passwords and list picker
    i haven't done it yet tho
    ;(
    Offline

    0
    ReputationRep:
    This website kinda helps. Just change all the csv's to txt files and it should (Haven't tried fully) work

    http://stackoverflow.com/questions/3...-in-a-csv-file
    Offline

    0
    ReputationRep:
    http://stackoverflow.com/questions/3...-in-a-csv-file


    This website helps. Just change all the CSV's for txt and it should work
    Offline

    0
    ReputationRep:
    hello, i'm doing the same task can anyone show me the full code for task 1 please ?
    Offline

    0
    ReputationRep:
    def word():
    #Theres a Function to start code off.

    sentence= input("Enter a sentence")
    #In the start of the code you have to have a input satement.

    keyword= input("Input a keyword from the sentence")
    #You would have to pick a word that you typed.

    words = sentence.split(' ')
    #This code here has to slipts it and understand the code and puts it in toa better readeble way for the user.

    for (i, subword) in enumerate(words):
    #For this bit , i put it as for each word in the sentence can be read and picked out if the words.

    if (subword == keyword):
    #In this part of code subword is varible for i and i is there to find the subword and subword is there for keyword

    print(i+1)
    #all it does prints out the the position and there
    Offline

    8
    ReputationRep:
    (Original post by MathsAndChess)
    You might want to start with the following code:

    string = "ASK NOT WHAT YOUR COUNTRY CAN DO FOR YOU ASK WHAT YOU CAN DO FOR YOUR COUNTRY"
    stringWords = string.split()
    Im new to python. What does () do in this case, and in other cases? What is string.split?

    I don't understand what () is used for in python. Can you please explain?
    Offline

    0
    ReputationRep:
    mystr = "ASK NOT WHAT YOUR COUNTRY CAN DO FOR YOU ASK WHAT YOU CAN DO FOR YOUR COUNTRY"
    a = mystr.split(" ")
    k = dict()
    cnt = 1
    b = []
    for m in a:
    if m not in k:
    k[m] = str(cnt)
    cnt = cnt + 1
    b.append(k[m])
    print ",".join(b)
    Offline

    0
    ReputationRep:
    import csv text = "ASK NOT WHAT YOUR COUNTRY CAN DO FOR YOU ASK WHAT YOU CAN DO FOR YOUR COUNTRY"words = text.split() with open('output.csv', 'wb') as f_output: csv_output = csv.writer(f_output) csv_output.writerow([words.index(word)+1 for word in words])
    Offline

    0
    ReputationRep:
    import csv text = "ASK NOT WHAT YOUR COUNTRY CAN DO FOR YOU ASK WHAT YOU CAN DO FOR YOUR COUNTRY"

    words = text.split() with open('output.csv', 'wb' ) as f_output:

    csv_output = csv.writer(f_output)csv_output.

    writerow([words.index(word)+1 for word in words])
    Offline

    0
    ReputationRep:
    Does anyone know how to do the task 3:

    You have to remove capitalisation and punctuation then rebuild the sentence with capitalisation and punctuation
    Offline

    0
    ReputationRep:
    bit late but noone said you have to remove the caps and punc, levae it in and save 'ask' and Ask' as sperate words just like 'ask.' and 'ask' @ARZ123
    Offline

    0
    ReputationRep:
    (Original post by ARZ123)
    Does anyone know how to do the task 3:

    You have to remove capitalisation and punctuation then rebuild the sentence with capitalisation and punctuation
    bit late but noone said you have to remove the caps and punc, levae it in and save 'ask' and Ask' as sperate words just like 'ask.' and 'ask' @ARZ123
    Offline

    0
    ReputationRep:
    positions= [] #Assign position to a list
    sentence= input("Enter the sentence please: ").lower()
    sentence=sentence.split( )
    length=(len(sentence))
    word = input("Enter the word that you would like to search for please: ").lower()
    if word not in sentence:
    print ("Error ,'",word,"' is not in this sentence.")
    else:
    for x in range(0,length):
    if sentence[x]==word:
    positions.append(x+1)
    print(word,"is at positions", positions)
    Offline

    1
    ReputationRep:
    You guys still need help? I submitted this coursework like two months ago and got 43/45 (A*).
    Offline

    0
    ReputationRep:
    boiiiiiii, set me that ting
    Offline

    1
    ReputationRep:
    you know you'd **** both me and you over if you plagiarise it tho. lmfao don't **** about it boiiii
    Offline

    2
    ReputationRep:
    Hey, I've also been doing this task for the past couple weeks and i dont know what the hell im doing, could someone please help me out with task 1? i hate python );
    Offline

    0
    ReputationRep:
    (Original post by zxvs)
    You guys still need help? I submitted this coursework like two months ago and got 43/45 (A*).

    How did you do it imma cry. You don't have to give me the whole thing please help with some ideas I am so stuck our teacher left to new Zealand without teaching us anything
 
 
 
Poll
Do you agree with the PM's proposal to cut tuition fees for some courses?

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reply
Hide
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.