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
# -*- coding: utf-8 -*- | |
list1 = [1] | |
list2 = [2, 3] | |
list3 = [4, 5, 6] | |
list4 = list1 + list2 + list3 | |
print("list1:" + str(list1)) | |
print("list2:" + str(list2)) | |
print("list3:" + str(list3)) |
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
# -*- coding: utf-8 -*- | |
list = [2, 4, 8] | |
print("insert前:" + str(list)) | |
list.insert(2, 6) | |
print("insert後:" + str(list)) | |
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
# -*- coding: utf-8 -*- | |
list = [2, 4, 6, 8] | |
print("削除前:" + str(list)) | |
del list[1] | |
print("削除後:" + str(list)) | |
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
# -*- coding: utf-8 -*- | |
list = [2, 4, 6, 8, 6, 4] | |
print("削除前:" + str(list)) | |
list.remove(4) | |
print("削除後:" + str(list)) | |
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
# -*- coding: utf-8 -*- | |
list = [2, 4, 6, 8, 6, 4] | |
print("list内容:" + str(list)) | |
print("listの要素数:" + str(len(list))) | |
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
# -*- coding: utf-8 -*- | |
list = [5, 2, 3, 4, 1] | |
print("ソート前:" + str(list)) | |
list.sort() | |
print("ソート後:" + str(list)) |
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
# -*- coding: utf-8 -*- | |
list = [5, 2, 3, 4, 1] | |
print("ソート前:" + str(list)) | |
list.sort(reverse=True) | |
print("ソート後:" + str(list)) |
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
# -*- coding: utf-8 -*- | |
list = [5, 2, 3, 4, 1] | |
print("並び替え前:" + str(list)) | |
list.reverse() | |
print("並び替え後:" + str(list)) |
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
# -*- coding: utf-8 -*- | |
list = [5, 2, 3, 4, 1] | |
print("ソート前:" + str(list)) | |
list.sort() | |
print("ソート後:" + str(list)) | |
list.reverse() | |
print("逆順に並び替え:" + str(list)) |
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
# -*- coding: utf-8 -*- | |
from operator import itemgetter | |
list = [[300, 40, 9], [100, 60, 8], [200, 50, 7]] | |
print("ソート前:" + str(list)) | |
list.sort(key=itemgetter(0)) | |
print("ソート後(0番目の要素):" + str(list)) | |
list.sort(key=itemgetter(1)) |