|
Empty List
mylist = []
append to a list:
mylist.append(123)
Simple List
mylist = [1,2,13,13,35,6,7,8,9]
append to a list:
mylist.append(123)
Print a list:
print('print with foreach:')
for item in mylist:
print(item)
print()
print('Output with for range:')
for i in range(0,len(mylist),1):
print( mylist[i] )
Methods
Append to a list: mylist.append(123)
Count from a list: anz=len(mylist)
Delete the complete List:
list.clear()
How many items are in the list: len(mylist)
Min-item: min(mylist)
Max-item: max(mylist)
How often are then '6' in the list: mylist.count(6)
the position of the '13': mylist.index(13)
Is '6' in the list): if 6 in mylist:
Is '6' not in the list): if 6 not in mylist:
insert at position: mylist.insert(1,42)
delete the last item: mylist.pop()
get the i-te item and delete it: mylist.pop(i)
insert at position: mylist.insert(1,42)
Revers the list: mylist.reverse()
Sort
sort the list: mylist.sort()
sort the list with the key : mylist.sort(key=len)
sort the list with the key : mylist.sort(key=len, reverse)
Copy
copy of a list: newList = mylist[:]
Lambda
resultList = = list(filter(lambda x: '35' in x, mylist)
|
|