Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python
Python
  1. โปรแกรม Python หาองค์ประกอบร่วมแรกระหว่าง 2 Linked List

    ภาพรวม เมื่อต้องการหาองค์ประกอบร่วมที่เกิดขึ้นครั้งแรกระหว่าง 2 Linked List จะนิยามเมธอดเพิ่มองค์ประกอบ และเมธอดหาองค์ประกอบร่วมแรก ตัวอย่างโค้ด class Node: def __init__(self, data): self.data = data self.next = None class LinkedList_structure: def __init__(self): s

  2. โปรแกรม Python หาจำนวนครั้งที่เกิดของทุกองค์ประกอบใน Linked List

    ภาพรวม เมื่อต้องการหาจำนวนครั้งที่เกิดของทุกองค์ประกอบใน Linked List จะนิยามเมธอดสำหรับเพิ่มองค์ประกอบ แสดงองค์ประกอบ และนับจำนวนครั้งที่เกิดขององค์ประกอบทั้งหมด ตัวอย่างโค้ด class Node: def __init__(self, data): self.data = data self.next = None class LinkedList_structure:

  3. โปรแกรม Python สำหรับย้อนกลับเฉพาะ N องค์ประกอบแรกของ Linked List

    ภาพรวม เมื่อต้องการย้อนกลับชุดเฉพาะขององค์ประกอบใน Linked List จะนิยามเมธอดชื่อ reverse_list ซึ่งจะวนลูปผ่านรายการและย้อนกลับองค์ประกอบที่ระบุ ตัวอย่างโค้ด class Node: def __init__(self, data): self.data = data self.next = None class LinkedList_structure: def __init__(self)

  4. หา Node กลาง (Middle Node) ของ Linked List ใน Python

    หา Node กลางของ Linked List โดยนับความยาวก่อน แล้วเดินไปที่ตำแหน่ง (length-1)//2 ตัวอย่างโค้ด class Node: def __init__(self, data): self.data = data self.next = None class LinkedList_structure: def __init__(self): self.head = None self.last_node = None de

  5. หา Node ที่ n จากท้ายของ Linked List ใน Python

    หา Node ที่ n จากท้ายโดยคำนวณความยาว List ก่อน แล้วเดินจากหัวไป (length - n) ก้าว ตัวอย่างโค้ด class Node: def __init__(self, data): self.data = data self.next = None class LinkedList_structure: def __init__(self): self.head = None self.last_node = None d

  6. แปลงสมาชิกใน List of Tuples ให้เป็น Float ใน Python

    วนลูปแต่ละ Tuple และแต่ละสมาชิก ใช้ isalpha() ตรวจสอบว่าเป็นตัวอักษร ถ้าไม่ใช่แปลงเป็น float ตัวอย่างโค้ด my_list = [(45, Jane), (11, Will), (37.68, 86.78), (Rob, 89.90)] print(The list is : ) print(my_list) my_result = [] for tup in my_list: temp_val = [] for elem in tup: if elem.i

  7. ตรวจสอบ Palindrome ด้วย Stack ใน Python

    ใช้ Stack เก็บตัวอักษร แล้ว Pop ออกมาเป็นลำดับกลับ เพื่อเปรียบเทียบกับสตริงต้นฉบับ ตัวอย่างโค้ด class Stack_structure: def __init__(self): self.items = [] def check_empty(self): return self.items == [] def push_val(self, data): self.items.append(data) def pop_

  8. จัดเรียง Tuples ตามจำนวนหลักตัวเลขรวมใน Python

    ใช้ sorted() ร่วมกับ lambda คำนวณจำนวนหลักตัวเลขรวมในแต่ละ Tuple แล้วจัดเรียง ตัวอย่างโค้ด my_list = [(11, 23, 45, 678), (34, 67), (653,), (78, 99, 23, 45), (67, 43)] print(The list is : ) print(my_list) my_result = sorted(my_list, key=lambda tup: sum([len(str(ele)) for ele in tup])) print(The sort

  9. หาตัวเลขอันดับ n ที่น้อยที่สุดใน List ด้วยเวลา Linear (Expected Linear Time) ใน Python

    ใช้ Quickselect หาตัวที่ n น้อยที่สุด (nth Smallest) ในเวลาเฉลี่ย O(n) ตัวอย่างโค้ด def select_smallest(my_list, beg, end, i): if end - beg <= 1: return my_list[beg] pivot_val = start_partition(my_list, beg, end) k = pivot_val - beg + 1 if i k: return select_smallest

  10. ดึงนิยามตาราง (Table Definition) จากฐานข้อมูลใน AWS Glue Data Catalog ด้วย Boto3

    ใช้ Boto3 ดึงนิยามตารางทั้งหมด หรือตารางที่ Match ตาม Regular Expression จาก Database ใน AWS Glue Data Catalog ตัวอย่าง ดึงนิยามตารางใน Database QA-test ตาราง security และ employee ขั้นตอน/อัลกอริทึม Import boto3 และ botocore.exceptions.ClientError database_name บังคับ, regular_expression_for_t

  11. ดึงรายละเอียด Trigger จาก AWS Glue Data Catalog ด้วย Boto3

    ใช้ Boto3 ดึงข้อมูลเมตาของ Trigger เฉพาะตัวจาก AWS Glue Data Catalog ตัวอย่าง ดึงข้อมูล Trigger ชื่อ 01_PythonShellTest1 ขั้นตอน/อัลกอริทึม Import boto3 และ botocore.exceptions.ClientError trigger_name เป็นพารามิเตอร์บังคับ สร้าง AWS Session และ Glue Client เรียก get_trigger(Name=trigger_na

  12. ดึงรายละเอียด Triggers ทั้งหมดที่เชื่อมโยงกับ Job จาก AWS Glue Data Catalog ด้วย Boto3

    ใช้ Boto3 ดึง Triggers ที่เกี่ยวข้องกับ Job เฉพาะใน AWS Glue Data Catalog ตัวอย่าง ดึง Triggers ที่เชื่อมโยงกับ Job ชื่อ employee_details ขั้นตอน/อัลกอริทึม Import boto3 และ botocore.exceptions.ClientError job_name เป็นพารามิเตอร์ทางเลือก (ถ้าไม่ระบุ จะดึง Triggers ทั้งหมด) สร้าง AWS Session

  13. ดึงรายละเอียด User-Defined Function เฉพาะตัวจาก AWS Glue Data Catalog ด้วย Boto3

    ใช้ Boto3 ดึงข้อมูล Function Definition เฉพาะตัวจากฐานข้อมูลใน AWS Glue Data Catalog ตัวอย่าง ดึงข้อมูลฟังก์ชันชื่อ insert_employee_record ในฐานข้อมูล employee ขั้นตอน/อัลกอริทึม Import boto3 และ botocore.exceptions.ClientError database_name และ function_name เป็นพารามิเตอร์บังคับ สร้าง AWS S

  14. ดึงรายละเอียด Function Definitions หลายตัวจาก AWS Glue Data Catalog ด้วย Boto3

    ใช้ Boto3 ดึงข้อมูล User Defined Functions หลายฟังก์ชันจากฐานข้อมูลใน AWS Glue Data Catalog ปัญหา ใช้ Boto3 ใน Python ดึงรายละเอียด Function Definitions หลายตัวจาก Database(s) ใน AWS Glue Data Catalog ขั้นตอน/อัลกอริทึม Import boto3 และ botocore.exceptions.ClientError database_name และ regular_

  15. หาตัวเลขอันดับ n ที่มากที่สุดใน List ด้วยเวลา Linear (Expected Linear Time) ใน Python

    ใช้ алгоритม Quickselect (คล้าย QuickSort แต่วิ่งด้านเดียว) หาตัวที่ n มากที่สุดในเวลาเฉลี่ย O(n) ตัวอย่างโค้ด def select_largest(my_list, beg, end, i): if end - beg <= 1: return my_list[beg] pivot_val = start_partition(my_list, beg, end) k = end - pivot_val if i k:

  16. โปรแกรม Python กลับลำดับ Stack ด้วย Recursion (Recursive Stack Reversal)

    กลับลำดับ Stack โดยใช้ Recursion: นำสมาชิกบนสุดออก เรียกฟังก์ชันซ้ำจน Stack ว่าง แล้วนำสมาชิกที่นำออกไปใส่ที่ก้น Stack ทีละตัว ตัวอย่างโค้ด class Stack_structure: def __init__(self): self.items = [] def check_empty(self): return self.items == [] def push_val(self, data):

  17. โปรแกรม Python สร้าง Stack ด้วย Queue เดียว (Implement Stack using One Queue)

    ใช้ Queue เดียว จำลอง Stack โดยการหมุนข้อมูล (dequeue แล้ว enqueue กลับ) จนสมาชิกล่าสุดอยู่หน้าสุด ตัวอย่างโค้ด class Stack_structure: def __init__(self): self.q = Queue_structure() def check_empty(self): return self.q.check_empty() def push_val(self, data): self.

  18. โปรแกรม Python สร้าง Stack ด้วย Queue สองอัน (Implement Stack using Two Queues)

    ใช้ Queue สองอัน จำลองพฤติกรรม Stack (LIFO) โดยย้ายข้อมูลระหว่าง Queue เพื่อให้สมาชิกล่าสุดอยู่หน้าสุด ตัวอย่างโค้ด class Stack_structure: def __init__(self): self.queue_1 = Queue_structure() self.queue_2 = Queue_structure() def check_empty(self): return self.queue_2.

  19. วิธีดึงรายละเอียด Workflow จาก AWS Glue Data Catalog ด้วย Boto3

    บทความนี้แสดงวิธีใช้ Boto3 (AWS SDK for Python) ดึงข้อมูลเมตาของ Workflow จาก AWS Glue Data Catalog ปัญหา ใช้ Boto3 ใน Python เพื่อดึงข้อมูลเมตาของ Workflow ที่สร้างในบัญชี AWS ของคุณ ขั้นตอน/อัลกอริทึม Import boto3 และ botocore.exceptions.ClientError สำหรับจัดการข้อผิดพลาด workflow_name เป็นพา

Total 9001 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:261/451  20-คอมพิวเตอร์/Page Goto:1 255 256 257 258 259 260 261 262 263 264 265 266 267