0

I am getting this:

0.0  angry27.56%
0.0  disgust0.0%
0.0  fear18.75%
0.0  happy14.47%
0.0  sad5.34%
0.0  surprise14.96%
0.0  neutral18.92%

I want to get this:

0.0  angry27.56%, disgust0.0%, fear18.75%, happy14.47%, sad5.34%, surprise14.96%, neutral18.92%

I am using this code:

emotion = ""
        for i in range(len(predictions[0])):
            emotion = "%s%s%s" % (emotions[i], round(predictions[0][i]*100, 2), '%')
            print(str(sec)+ "  " + emotion)
1

2 Answers 2

1
print(str(sec)+ "  " + emotion,end=', ')

end=' ' parameter inside the print statement can be used to print output in a single line....

Sign up to request clarification or add additional context in comments.

3 Comments

I tried it but all in vain!!! Now I am getting 0.0 angry 27.56% 0.0 disgust 0.0% 0.0 fear 18.75% 0.0 happy 14.47% 0.0 sad 5.34% 0.0 surprise 14.96% 0.0 neutral 18.92% 0.04 angry 1.0% 0.04 disgust 0.0% 0.04 fear 5.16% 0.04 happy 1.97% 0.04 sad 1.19% 0.04 surprise 5.57% 0.04 neutral 85.12% 0.08 angry 0.51% 0.08 disgust 0.0% 0.08 fear 5.36% 0.08 happy 0.3% 0.08 sad 1.27% 0.08 surprise 5.47% 0.08 neutral 87.08% 0.12 angry 0.82% 0.12 disgust 0.0% 0.12 fear 5.5% 0.12 happy 0.15% 0.12 sad 2.65% 0.12 surprise 2.45% 0.12 neutral 88.42%
Use end=', ' comma and space inside single quote and execute it again...
1

First create a empty list then append all values of emotion in it then use join() to combine elements of list :

emotion = ""
res = []
for i in range(len(predictions[0])):
    emotion = "%s%s%s" % (emotions[i], round(predictions[0][i] * 100, 2), '%')
    res.append(emotion)
print(str(sec), end=" ")
print(", ".join(res))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.