-
Notifications
You must be signed in to change notification settings - Fork 0
python list
stachulemko edited this page Aug 30, 2023
·
15 revisions
l=[]
l=["a","b","c",1]
l[2] = 3 #podmiana elementu 3 w liscie
l=list(range(10)) # lista z liczbami od zera do 10 szybaka do wygenerowania
l=["a","b","c",1]
l.insert(3,3) #1.pozycja wstawienia 2.element do wstawienia
l.append() #wstawianie elementu na koniec
print("ilosc:",list.count(3)) #count()3 # ilosc powtarzajacych sie w liscie w tym przypadku chodzi ile powtarza sie 3
l=["a","b","c",1]
print(lista.index("c") # zwraca pozycje w tym przykladzie pozycja jest 2
l.remove("f") #usuwa pierwsze wystepnie f !!!
listname[start_index : end_index : step] - wzor
end index ostatniego elementu który już nie wchodzi wycinka
my_list = [5, 8, 'Tom', 7.50, 'Emma']
# slice first four items
print(my_list[:4])
# Output [5, 8, 'Tom', 7.5]
# print every second element
# with a skip count 2
print(my_list[::2])
# Output [5, 'Tom', 'Emma']
# reversing the list
print(my_list[::-1])
# Output ['Emma', 7.5, 'Tom', 8, 5]
# Without end_value
# Stating from 3nd item to last item
print(my_list[3:])
# Output [7.5, 'Emma']
append() function add item to the last place
list.append("kupa")
insert(position,elemnt) --- fuction add element on the position
list.insert(3, [25, 50, 75])
names = ['Jerry', 'Kramer', 'Elaine', 'George', 'Newman']
# Rewrite the for loop to use enumerate
indexed_names = []
for i,name in enumerate(names):
index_name = (i,name)
indexed_names.append(index_name)
print(indexed_names)
# Rewrite the above for loop using list comprehension
indexed_names_comp = [(i,name) for i,name in enumerate(names)]
print(indexed_names_comp)
# Unpack an enumerate object with a starting index of one
indexed_names_unpack = [*enumerate(names,1)]
print(indexed_names_unpack)
names = ['Jerry', 'Kramer', 'Elaine', 'George', 'Newman']
# Use map to apply str.upper to each element in names
names_map = map(str.upper,names)
# Print the type of the names_map
print(type(names_map))
# Unpack names_map into a list
names_uppercase = [*names_map]
# Print the list created above
print(names_uppercase)

---jak uzywac zipa !!!
