How to use subprocess commands inside for loop

Hi, I want to know how to use subprocess in side for loops, I want to use iteratable value in command . I write below code but no use

import os
import subprocess as sp
list1 = sp.getoutput (“pgrep Java”)
for process in list:
Xmx = sp.getoutput ("ps -p eww process | grep -oi “xmx\w*”)

I want to execute the command but process need to change for every loop

One way is to construct a process list and iterate through said list.