Home > Net >  I was learning django and I dont understand what's happening here, what is the logic
I was learning django and I dont understand what's happening here, what is the logic

Time:06-21

 if removepunc == "on":
    punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
    analyzed = ""
    for char in djtext:
        if char not in punctuations:
            analyzed = analyzed   char
    params = {'purpose':'Removed Punctuations', 'analyzed_text': analyzed}
    return render(request, 'analyze.html', params)

else:
    return HttpResponse("Error")

So basically this removes punctuations from a sentence and I'm not getting the loop part of the program. If anyone could explain, it would be great! Thanks

CodePudding user response:

you have djtext string which you scroll on with the for: for char in djtext

for example, if djtext='abc' then with for loop on it, char is 'a' in the first loop after 'b' after 'c'.

in this line if char not in punctuations, is checked that if char not into punctuations till concatenate char with analyzed string.

in the end:

    params = {'purpose':'Removed Punctuations', 'analyzed_text': analyzed}
    return render(request, 'analyze.html', params)

response data is getting ready then data that is params with analyze.html file return and render from django view.

  • Related