import os, glob
flist=[]
eset = set()
for i in glob.glob("*"):
    if len(i.split(sep='.'))>1:
        flist.append(i)
for i in flist:
    eset.add(i.split(sep=".")[-1])
def createDirs():
    for i in eset:
        try:
            os.makedirs(i+"_files")
        except FileExistsError:
            continue
def arrange():
    for i in flist:
        try:
            os.rename(i, i.split(sep=".")[-1]+"_files/"+i)
        except (OSError, IndexError):
            continue
createDirs()
arrange()
