1
00:00:00,820 --> 00:00:05,140
In this video, we're going to follow up on a raise by discussing a very similar data structure called

2
00:00:05,140 --> 00:00:10,030
a tuple, and you'll sometimes also hear this pronounced as tuple, totally up to you, either tuple

3
00:00:10,030 --> 00:00:10,630
or tuple.

4
00:00:11,530 --> 00:00:12,580
Either way, you want to do it.

5
00:00:12,970 --> 00:00:15,670
So, as usual, definition examples and so on.

6
00:00:16,270 --> 00:00:16,510
All right.

7
00:00:16,510 --> 00:00:17,830
So first off, quick definition.

8
00:00:18,310 --> 00:00:23,520
So when we are working with a tuple or a tuple, we have something that looks very similar to an array,

9
00:00:23,560 --> 00:00:24,540
very, very similar.

10
00:00:24,940 --> 00:00:29,800
But the big difference here is that we are going to have every element inside of this array looking

11
00:00:29,800 --> 00:00:33,400
thing represent one specific property about some record.

12
00:00:33,910 --> 00:00:39,070
So whereas an array tells us a bunch of different records or organizes a collection of different records,

13
00:00:39,400 --> 00:00:44,410
a tuple usually contains multiple different properties to describe one single thing.

14
00:00:45,380 --> 00:00:50,330
And as a follow up to that, usually inside of a couple, we will mix and match many different types

15
00:00:50,330 --> 00:00:51,350
of data inside there.

16
00:00:52,100 --> 00:00:53,540
So let's take a look at a quick example.

17
00:00:54,200 --> 00:00:54,620
All right.

18
00:00:54,620 --> 00:00:57,830
I want you to imagine that we've got some object like the one you see right here.

19
00:00:58,220 --> 00:01:02,900
And the goal of this object is to represent a drink, like, in this case, soda or pop, whatever you

20
00:01:02,900 --> 00:01:03,890
want to refer to it as.

21
00:01:04,519 --> 00:01:10,160
So maybe inside this object, we have a color property that is a string of brown carbonated that is

22
00:01:10,160 --> 00:01:16,230
a billion of true and sugar that is meant to represent the sugar content of the soda in grams.

23
00:01:16,250 --> 00:01:17,450
So that will be a number here.

24
00:01:17,840 --> 00:01:22,700
So as you might guess, this would represent maybe like Coca-Cola or Pepsi or something like that.

25
00:01:23,580 --> 00:01:28,220
So representing a drink or a soda with an object like this, I think makes a lot of sense.

26
00:01:28,250 --> 00:01:34,100
If you're coming particularly from a JavaScript background, we've got one object to represent one drink.

27
00:01:34,400 --> 00:01:38,750
And this object has some properties that describe what is going on with this singular drink.

28
00:01:39,640 --> 00:01:44,200
Now, just for fun, I want to take this object right here, and I just want to try to represent it

29
00:01:44,200 --> 00:01:46,120
with a slightly different data structure.

30
00:01:46,720 --> 00:01:49,990
Let's try to represent this object with an array instead.

31
00:01:50,590 --> 00:01:51,470
So how can we do that?

32
00:01:52,120 --> 00:01:55,270
Well, maybe we would say that we would take each these values.

33
00:01:55,270 --> 00:01:56,320
So like Brown.

34
00:01:57,310 --> 00:01:57,910
True.

35
00:01:59,300 --> 00:02:03,200
And then 40 and stick them into this array like so.

36
00:02:04,260 --> 00:02:09,120
So now we have a slightly different looking data structure that still represents a drink.

37
00:02:10,060 --> 00:02:14,200
And turning this into this, a raid right here, we have lost a little bit of information.

38
00:02:14,560 --> 00:02:19,660
In other words, you and I as developers can very easily look at a object declaration like this right

39
00:02:19,660 --> 00:02:25,600
here and very quickly understand, OK, the colors brown carbonate is true and sugar is 40.

40
00:02:26,290 --> 00:02:31,400
When we start to represent this object as an array, we've lost those different property labels on here.

41
00:02:31,780 --> 00:02:37,510
And so you and I as developers would have to memorize the fact that the first element inside this array

42
00:02:37,690 --> 00:02:39,780
is supposed to be a string representing the color.

43
00:02:40,300 --> 00:02:44,860
The second element is supposed to be a boolean representing whether or not the drink is carbonated.

44
00:02:45,520 --> 00:02:49,270
And then the third element inside there is a number representing these sugar content.

45
00:02:50,260 --> 00:02:55,180
So the big difference between representing this as an object and something that looks like an array

46
00:02:55,300 --> 00:03:01,690
is really just that loss of information in these labels no longer is our code really self labeling.

47
00:03:02,050 --> 00:03:05,440
Instead, we have to kind of memorize the order of properties inside of appear.

48
00:03:06,290 --> 00:03:13,010
So this is exactly what a tuple is, we have what looks like an array and we put in our property values

49
00:03:13,010 --> 00:03:15,280
into that array in a very specific order.

50
00:03:15,980 --> 00:03:17,750
So the ordering part is really critical.

51
00:03:18,140 --> 00:03:23,810
If we start to arbitrarily swap around elements inside of here, we are no longer going to understand

52
00:03:23,840 --> 00:03:26,630
which different value represents which property.

53
00:03:27,440 --> 00:03:32,360
So if you and I have memorized, like as developers, that this array is always supposed to tell us

54
00:03:32,390 --> 00:03:38,300
the color, then the carbonation and then the sugar content, and we swap some elements inside of here

55
00:03:38,900 --> 00:03:40,280
and we don't have those labels.

56
00:03:40,580 --> 00:03:45,470
Now, this is kind of a meaningless record because we're now trying to indicate that our color is 40.

57
00:03:46,130 --> 00:03:48,770
Carbonation is true and sugar content is brown.

58
00:03:49,290 --> 00:03:54,410
So when we work at the tuple, we have a fixed series of elements or a fixed order, I should say.

59
00:03:55,510 --> 00:03:58,270
All right, now, let's take a quick pause right here, we're going to come back to the next section,

60
00:03:58,390 --> 00:04:02,020
get some more examples around tuples and start to write out some code around them.

61
00:04:02,350 --> 00:04:04,410
So quick pause and I'll see you in just a minute.

