How to compress certain code

depression:
Alright so, say you got pins 2 - 8 being used for a 7 segment display, (2=A, 3=B...) Since im new to this stuff, I use the raw coding way which consists of like if input = 1 { digitalWrite(1, HIGH) digitalWrite(3, HIGH) } and so forth, is there a way to compress this?

First, you make an array (look up table) with your segment pins.

const byte SegmentsLUT[7] = {2, 3, 4, 5, 6, 7, 8};

Next, you make an array of bit masks where the binary value corresponds to the on/off state of each segment for a numeral 0-9 with 2^7 representing segment A, 2^1 representing segment G and 2^0 always 0. I have written these in binary notation so the segment value is evident.

const byte NumbersLUT[10] = {B11111100, B01100000, B11011010, B11110010, B01100110, B10110110, B10111110, B11100000, B11111110, B11110110};

Last, you write a function which when called and passed a value from 0-9 will iterate over the pin array using the bit mask from the number array.

void displayRefresh(byte numeral) {
    digitalWrite(CommonPin, LOW);// HIGH for common cathode
    for (int i = 0; i < 7; i++) digitalWrite(SegmentsLUT[i], ((NumbersLUT[numeral] & (0x01 << i)) ? LOW : HIGH));// swap HIGH and LOW for common cathode
    digitalWrite(CommonPin, HIGH);// LOW for common cathode
  }
}