appending multiple values to a list python code example

Example 1: append two items to list

my_list = ['a']
# You can use list.append(value) to append a single value:
my_list.append('b')
# my_list should look like ['a','b']

# and list.extend(iterable) to append multiple values.
my_list.extend(('b','c'))
# my_list should look like ['a','b','c']

Example 2: append two list of number to one python

listone = [1,2,3]
listtwo = [4,5,6]
mergedlist = []
mergedlist.extend(listone)
mergedlist.extend(listtwo)

Example 3: in array php multiple values

$haystack = array(...);

$target = array('foo', 'bar');

if(count(array_intersect($haystack, $target)) == count($target)){
    // all of $target is in $haystack
}

if(count(array_intersect($haystack, $target)) > 0){
    // at least one of $target is in $haystack
}

Example 4: python append multiple values

list.extend(val1,val2,val3....)
list.extend( [val1,val2],val3,val4,[val5,val6,val7])
#any combination of integers, strings, lists and tuples works

Tags:

Php Example