Appending a list on Arduino??

What is the most simple way to add or append an integer to the end of a list. In python this is VERY simple listtname.append(2) will get the job done. I can even find ways to append strings but not integers. how can this be the case. Also how do you add an integer to the end of an array? such that if you had a list "List1 = [1,2,3,4] and wanted to add an additional number on the end you could and it would look like List1 = [1,2,3,4,5]

How do you create a simple dictionary in Arduino similar to a python dictionary?

Actually we don't have dictionary in arduino. You can use ARRAY which is similar to dictionary in use but it only supports data of a particular type at a time and not mixed.

char x[10]; // here variable x will support only characters;
x[0] = 'a';
x[1] = 'd';
x[2] = 'a';
x[3] = 'm';

But you can create a structure or a CLASS for mixed content which can be used in a similar manner.

For example:

class student { //creating a class
int roll_no;
char name[20];
int class;
}

student s1; //creating a class instance or object
s1.name = "Neha"; //assigning values to class members
s1.roll_no = 22;
s1.class = 6;

//Now u can access the class members through the object
s1.name will give the name, s1.class will give the class and so on.

to add a list at the end of the array you need to know the index of the last element in the array.
In your case to add 5 in List1 the following statement is necessary-

List[4] = 5;

How big will this list be getting? And what Arduino board are you using?

What you're asking for is called dynamic memory allocation. A quick Google search will show you why it's a bad idea on resource poor microcontrollers.

Your best bet is to declare your array to the biggest size you think you will need it to be or that your Arduino can handle.

Aunullah:
to add a list at the end of the array you need to know the index of the last element in the array.
In your case to add 5 in List1 the following statement is necessary-

List[4] = 5;

This is completely wrong. That line will write off the end off the array into undefined memory (and possibly over something you need).

I have suggested to the moderator to merge this with your other Thread as the answer will be essentially the same.

The concepts you are enquiring about involve dynamic memory allocation. That works fine in the almost unlimited memory on a PC but it is an almost certain recipe for a crash due to memory corruption in the small SRAM of an Arduino.

On an Arduino it is much safer to define the maximum size of all data structures (such as arrays) when writing the program.

...R

A struct or class storing a key and a value is probably the closest you can get. An array of them would be a dictionary. Add some functions to find a value based on a key and to add or remove a key/value pair.

Do not make it dynamic, just use a fixed array to prevent possible memory issues.

Threads merged as requested.