7800X is 6C/12T @ 3.5GHz, 7700K is 4C/8T @ 4.2GHz. Assuming you don't overclock either of them, the 7700K is better for gaming.
If you do overclock, then the 7800X should be able to reach 4.0GHz fairly easily, but it would still not really outperform the 7700K. Perhaps in a couple years once game developers have decided that the majority of people who would use more than 4C/8T are on such a platform and would go ahead and design their game to run better on 6C/8C/10C CPUs then you would see the 7800X outperforms the 7700K. That is to say... intrinsically, the 7800X is a more powerful CPU but you need programs to take advantage of it and we're not there yet. As it currently stands, the higher clock rate from the 7700K will be more useful for gaming. Also consider that the 7700K has a good heat spreader while the 7800X uses thermal paste so you're less likely to overclock the 7800X as high as the 7700K.
The advantage that the 7800X has is related to the X299 platform over the Z270 platform. X299 has quad channel memory versus Z270's dual channel, and the 7800X has 28 PCIe lanes (IIRC 7700K has 16 lanes). If your build consists of a motherboard, CPU, RAM, SATA drives, single GPU, and at most two PCIe x1 cards then the number of PCIe lanes and configuration of onboard ports literally doesn't matter for you. I've found that about 90% of builds fall into this category. (Even the PCIe x1 cards are rarely used, typically just for WiFi, and they would use the PCIe x1 slots that are connected to the chipset not the CPU so they do not interfere with the GPU or NVMe configuration.)