Last active
August 16, 2021 15:21
-
-
Save osamaayub/4c35d0c7cdeee68ca57fe6917376fee3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# changing the Lists items | |
List = ["Apple", "Grape", "Mango", "Apple", "Grape"] | |
List[0] = "Guava" | |
# change A list of items up to range | |
# insert an item in a list | |
List[0:2] = ["Orange", " Cherry"] | |
List.insert(3, " Watermelon") | |
# add in a List | |
List.append("Strawberry") | |
# Extend List | |
L = ["Car", " bus", "truck"] | |
List.extend(L) | |
mytuple = ("Jawad", "23") | |
List.extend(mytuple) | |
thisdic = ({"Name": "osama", "Age": 23, "year": 1984}) | |
List.extend(thisdic) | |
# remove a specific item | |
List.remove("Name") | |
# remove a specific item | |
List.pop(1) | |
print(List) | |
# remove last element from the list | |
List.pop() | |
print(List) | |
# print a list using for loop | |
for i in List: | |
print(i) | |
# print a List using Indexing | |
for i in range(len(List)): | |
print(List[i]) | |
# print a list using while loop | |
i = 0 | |
while i < len(List): | |
print(List[i]) | |
i += 1 | |
# comprehension of a loop | |
[print(x) for x in List] | |
# sorting an List | |
List.sort() | |
print(List) | |
#reverse a List | |
List.sort(reverse=True) | |
print(List) | |
# copy data from one lists to another | |
L = [0] | |
L = List.copy() | |
print(L) | |
#concetenate the two Lists | |
L2 = ['May', 'June', 'july'] | |
L3 = L + L2 | |
print(L3) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment