Lia  Haley

Lia Haley

1598876400

The World Needs Web Accessibility Now More Than Ever

A background with a top view of a laptop keyboard and text that reads, the web has become less accessible.

I attended a talk last year by Mike Gifford where he said, “the web has actually become LESS accessible since 2011.”

It’s cheap and easy for anyone to create a website these days, and hardly anyone considers accessibility. And why would you? If it’s not in your daily purview, it’s not going into your list of website requirements. Heck, most people don’t even think of the end user, Disabled or not, when creating a website. Especially not when they use a “drag and drop” style website creation platform. Nothing against those, just that those platforms often don’t have accessibility built in, and it’s very difficult to make them so, even if you had the desire.

The other aspect working against website accessibility is when you say the word, ‘accessibility’ not every even has a concept of what that means. I asked a website designer recently if he makes accessible websites, and he said, “yes…we add alt-tags to all our images.” Ummmm, OK. Great. But can a screen reader read your website?

So let’s dispel some myths and dive a bit into the world of what it means to implement web accessibility.

First off, it’s important to note that the USA actually has very clear legislation regarding accessibility. It’s called the Americans With Disabilities Act, and it includes websites. US-based companies should be aware that not having a minimally accessible business website can leave you open to a law suit and fines. I’m Canadian with a Canadian registered company, so I do not actually have to worry about getting sued for not having an accessible website, but bonus, I have one anyway! I’ll explain why it’s beneficial to have an accessible website even if you are not a US-based company.

#accessibility #web-accessibility #accessibility-design #accessibility-testing #amazon web services

What is GEEK

Buddha Community

The World Needs Web Accessibility Now More Than Ever
Lia  Haley

Lia Haley

1598876400

The World Needs Web Accessibility Now More Than Ever

A background with a top view of a laptop keyboard and text that reads, the web has become less accessible.

I attended a talk last year by Mike Gifford where he said, “the web has actually become LESS accessible since 2011.”

It’s cheap and easy for anyone to create a website these days, and hardly anyone considers accessibility. And why would you? If it’s not in your daily purview, it’s not going into your list of website requirements. Heck, most people don’t even think of the end user, Disabled or not, when creating a website. Especially not when they use a “drag and drop” style website creation platform. Nothing against those, just that those platforms often don’t have accessibility built in, and it’s very difficult to make them so, even if you had the desire.

The other aspect working against website accessibility is when you say the word, ‘accessibility’ not every even has a concept of what that means. I asked a website designer recently if he makes accessible websites, and he said, “yes…we add alt-tags to all our images.” Ummmm, OK. Great. But can a screen reader read your website?

So let’s dispel some myths and dive a bit into the world of what it means to implement web accessibility.

First off, it’s important to note that the USA actually has very clear legislation regarding accessibility. It’s called the Americans With Disabilities Act, and it includes websites. US-based companies should be aware that not having a minimally accessible business website can leave you open to a law suit and fines. I’m Canadian with a Canadian registered company, so I do not actually have to worry about getting sued for not having an accessible website, but bonus, I have one anyway! I’ll explain why it’s beneficial to have an accessible website even if you are not a US-based company.

#accessibility #web-accessibility #accessibility-design #accessibility-testing #amazon web services

Evolution in Web Design: A Case Study of 25 Years - Prismetric

The term web design simply encompasses a design process related to the front-end design of website that includes writing mark-up. Creative web design has a considerable impact on your perceived business credibility and quality. It taps onto the broader scopes of web development services.

Web designing is identified as a critical factor for the success of websites and eCommerce. The internet has completely changed the way businesses and brands operate. Web design and web development go hand-in-hand and the need for a professional web design and development company, offering a blend of creative designs and user-centric elements at an affordable rate, is growing at a significant rate.

In this blog, we have focused on the different areas of designing a website that covers all the trends, tools, and techniques coming up with time.

Web design
In 2020 itself, the number of smartphone users across the globe stands at 6.95 billion, with experts suggesting a high rise of 17.75 billion by 2024. On the other hand, the percentage of Gen Z web and internet users worldwide is up to 98%. This is not just a huge market but a ginormous one to boost your business and grow your presence online.

Web Design History
At a huge particle physics laboratory, CERN in Switzerland, the son of computer scientist Barner Lee published the first-ever website on August 6, 1991. He is not only the first web designer but also the creator of HTML (HyperText Markup Language). The worldwide web persisted and after two years, the world’s first search engine was born. This was just the beginning.

Evolution of Web Design over the years
With the release of the Internet web browser and Windows 95 in 1995, most trading companies at that time saw innumerable possibilities of instant worldwide information and public sharing of websites to increase their sales. This led to the prospect of eCommerce and worldwide group communications.

The next few years saw a soaring launch of the now-so-famous websites such as Yahoo, Amazon, eBay, Google, and substantially more. In 2004, by the time Facebook was launched, there were more than 50 million websites online.

Then came the era of Google, the ruler of all search engines introducing us to search engine optimization (SEO) and businesses sought their ways to improve their ranks. The world turned more towards mobile web experiences and responsive mobile-friendly web designs became requisite.

Let’s take a deep look at the evolution of illustrious brands to have a profound understanding of web design.

Here is a retrospection of a few widely acclaimed brands over the years.

Netflix
From a simple idea of renting DVDs online to a multi-billion-dollar business, saying that Netflix has come a long way is an understatement. A company that has sent shockwaves across Hollywood in the form of content delivery. Abundantly, Netflix (NFLX) is responsible for the rise in streaming services across 190 countries and meaningful changes in the entertainment industry.

1997-2000

The idea of Netflix was born when Reed Hastings and Marc Randolph decided to rent DVDs by mail. With 925 titles and a pay-per-rental model, Netflix.com debuts the first DVD rental and sales site with all novel features. It offered unlimited rentals without due dates or monthly rental limitations with a personalized movie recommendation system.

Netflix 1997-2000

2001-2005

Announcing its initial public offering (IPO) under the NASDAQ ticker NFLX, Netflix reached over 1 million subscribers in the United States by introducing a profile feature in their influential website design along with a free trial allowing members to create lists and rate their favorite movies. The user experience was quite engaging with the categorization of content, recommendations based on history, search engine, and a queue of movies to watch.

Netflix 2001-2005 -2003

2006-2010

They then unleashed streaming and partnering with electronic brands such as blu-ray, Xbox, and set-top boxes so that users can watch series and films straight away. Later in 2010, they also launched their sophisticated website on mobile devices with its iconic red and black themed background.

Netflix 2006-2010 -2007

2011-2015

In 2013, an eye-tracking test revealed that the users didn’t focus on the details of the movie or show in the existing interface and were perplexed with the flow of information. Hence, the professional web designers simply shifted the text from the right side to the top of the screen. With Daredevil, an audio description feature was also launched for the visually impaired ones.

Netflix 2011-2015

2016-2020

These years, Netflix came with a plethora of new features for their modern website design such as AutoPay, snippets of trailers, recommendations categorized by genre, percentage based on user experience, upcoming shows, top 10 lists, etc. These web application features yielded better results in visual hierarchy and flow of information across the website.

Netflix 2016-2020

2021

With a sleek logo in their iconic red N, timeless black background with a ‘Watch anywhere, Cancel anytime’ the color, the combination, the statement, and the leading ott platform for top video streaming service Netflix has overgrown into a revolutionary lifestyle of Netflix and Chill.

Netflix 2021

Contunue to read: Evolution in Web Design: A Case Study of 25 Years

#web #web-design #web-design-development #web-design-case-study #web-design-history #web-development

Dang  Tu

Dang Tu

1662380058

Các Cấu Trúc Dữ Liệu được Sử Dụng Phổ Biến Nhất Trong Python

Trong bất kỳ ngôn ngữ lập trình nào, chúng ta cần xử lý dữ liệu. Bây giờ, một trong những điều cơ bản nhất mà chúng ta cần làm việc với dữ liệu là lưu trữ, quản lý và truy cập nó một cách hiệu quả theo cách có tổ chức để nó có thể được sử dụng bất cứ khi nào được yêu cầu cho các mục đích của chúng ta. Cấu trúc dữ liệu được sử dụng để đáp ứng mọi nhu cầu của chúng tôi.

Cấu trúc dữ liệu là gì?

Cấu trúc dữ liệu là các khối xây dựng cơ bản của một ngôn ngữ lập trình. Nó nhằm mục đích cung cấp một cách tiếp cận có hệ thống để đáp ứng tất cả các yêu cầu được đề cập trước đó trong bài báo. Các cấu trúc dữ liệu trong Python là Danh sách, Tuple, Từ điển và Tập hợp . Chúng được coi là Cấu trúc dữ liệu ngầm định hoặc được tích hợp sẵn trong Python . Chúng tôi có thể sử dụng các cấu trúc dữ liệu này và áp dụng nhiều phương pháp cho chúng để quản lý, liên quan, thao tác và sử dụng dữ liệu của chúng tôi.

Chúng tôi cũng có các Cấu trúc Dữ liệu tùy chỉnh do người dùng xác định cụ thể là Ngăn xếp , Hàng đợi , Cây , Danh sách được Liên kếtĐồ thị . Chúng cho phép người dùng có toàn quyền kiểm soát chức năng của chúng và sử dụng chúng cho các mục đích lập trình nâng cao. Tuy nhiên, chúng tôi sẽ tập trung vào Cấu trúc dữ liệu tích hợp cho bài viết này.

Python cấu trúc dữ liệu ngầm

Python cấu trúc dữ liệu ngầm

DANH SÁCH

Danh sách giúp chúng tôi lưu trữ dữ liệu của mình một cách tuần tự với nhiều kiểu dữ liệu. Chúng có thể so sánh với mảng với ngoại lệ là chúng có thể lưu trữ các kiểu dữ liệu khác nhau như chuỗi và số cùng một lúc. Mỗi mục hoặc phần tử trong danh sách đều có một chỉ mục được chỉ định. Vì Python sử dụng lập chỉ mục dựa trên 0 , phần tử đầu tiên có chỉ mục là 0 và việc đếm vẫn tiếp tục. Phần tử cuối cùng của danh sách bắt đầu bằng -1 có thể được sử dụng để truy cập các phần tử từ cuối cùng đến đầu tiên. Để tạo một danh sách, chúng ta phải viết các mục bên trong dấu ngoặc vuông .

Một trong những điều quan trọng nhất cần nhớ về danh sách là chúng có thể thay đổi . Điều này đơn giản có nghĩa là chúng ta có thể thay đổi một phần tử trong danh sách bằng cách truy cập trực tiếp vào nó như một phần của câu lệnh gán bằng cách sử dụng toán tử lập chỉ mục. Chúng tôi cũng có thể thực hiện các thao tác trên danh sách của mình để có được đầu ra mong muốn. Chúng ta hãy đi qua đoạn mã để hiểu rõ hơn về danh sách và các hoạt động của danh sách.

1. Tạo danh sách

#creating the list
my_list = ['p', 'r', 'o', 'b', 'e']
print(my_list)

Đầu ra

['p', 'r', 'o', 'b', 'e']

2. Truy cập các mục từ Danh sách

#accessing the list 
 
#accessing the first item of the list
my_list[0]

Đầu ra

'p'
#accessing the third item of the list
my_list[2]
'o'

3. Thêm các mục mới vào danh sách

#adding item to the list
my_list + ['k']

Đầu ra

['p', 'r', 'o', 'b', 'e', 'k']

4. Loại bỏ các mục

#removing item from the list
#Method 1:
 
#Deleting list items
my_list = ['p', 'r', 'o', 'b', 'l', 'e', 'm']
 
# delete one item
del my_list[2]
 
print(my_list)
 
# delete multiple items
del my_list[1:5]
 
print(my_list)

Đầu ra

['p', 'r', 'b', 'l', 'e', 'm']
['p', 'm']
#Method 2:
 
#with remove fucntion
my_list = ['p','r','o','k','l','y','m']
my_list.remove('p')
 
 
print(my_list)
 
#Method 3:
 
#with pop function
print(my_list.pop(1))
 
# Output: ['r', 'k', 'l', 'y', 'm']
print(my_list)

Đầu ra

['r', 'o', 'k', 'l', 'y', 'm']
o
['r', 'k', 'l', 'y', 'm']

5. Danh sách sắp xếp

#sorting of list in ascending order
 
my_list.sort()
print(my_list)

Đầu ra

['k', 'l', 'm', 'r', 'y']
#sorting of list in descending order
 
my_list.sort(reverse=True)
print(my_list)

Đầu ra

['y', 'r', 'm', 'l', 'k']

6. Tìm độ dài của một danh sách

#finding the length of list
 
len(my_list)

Đầu ra

5

TUPLE

Tuple rất giống với danh sách với một điểm khác biệt chính là tuple là NGAY LẬP TỨC , không giống như một danh sách. Khi chúng tôi tạo một bộ hoặc có một bộ, chúng tôi không được phép thay đổi các phần tử bên trong nó. Tuy nhiên, nếu chúng ta có một phần tử bên trong một tuple, chính là một danh sách, thì chỉ khi đó chúng ta mới có thể truy cập hoặc thay đổi trong danh sách đó. Để tạo một bộ giá trị, chúng ta phải viết các mục bên trong dấu ngoặc đơn . Giống như danh sách, chúng tôi có các phương pháp tương tự có thể được sử dụng với các bộ giá trị. Hãy xem qua một số đoạn mã để hiểu cách sử dụng bộ giá trị.

1. Tạo Tuple

#creating of tuple
 
my_tuple = ("apple", "banana", "guava")
print(my_tuple)

Đầu ra

('apple', 'banana', 'guava')

2. Truy cập các mục từ Tuple

#accessing first element in tuple
 
my_tuple[1]

Đầu ra

'banana'

3. Chiều dài của một Tuple

#for finding the lenght of tuple
 
len(my_tuple)

Đầu ra

3

4. Chuyển đổi Tuple sang danh sách

#converting tuple into a list
 
my_tuple_list = list(my_tuple)
type(my_tuple_list)

Đầu ra

list

5. Đảo ngược Tuple

#Reversing a tuple
 
tuple(sorted(my_tuple, reverse=True)) 

Đầu ra

('guava', 'banana', 'apple')

6. Sắp xếp một Tuple

#sorting tuple in ascending order
 
tuple(sorted(my_tuple)) 

Đầu ra

('apple', 'banana', 'guava')

7. Xóa các phần tử khỏi Tuple

Để xóa các phần tử khỏi bộ tuple, trước tiên chúng tôi chuyển đổi bộ tuple thành một danh sách như chúng tôi đã làm trong một trong các phương pháp của chúng tôi ở trên (Điểm số 4), sau đó thực hiện theo cùng một quy trình của danh sách và loại bỏ rõ ràng toàn bộ bộ tuple, chỉ bằng cách sử dụng del tuyên bố .

TỪ ĐIỂN

Từ điển là một bộ sưu tập có nghĩa đơn giản là nó được sử dụng để lưu trữ một giá trị với một số khóa và trích xuất giá trị được cung cấp cho khóa. Chúng ta có thể coi nó như một tập hợp các cặp khóa: giá trị và mọi khóa trong từ điển được coi là duy nhất để chúng ta có thể truy cập các giá trị tương ứng tương ứng .

Một từ điển được biểu thị bằng cách sử dụng dấu ngoặc nhọn {} chứa các cặp key: value. Mỗi cặp trong từ điển được phân tách bằng dấu phẩy. Các phần tử trong từ điển không được sắp xếp theo thứ tự, trình tự không quan trọng khi chúng ta đang truy cập hoặc lưu trữ chúng.

Chúng MUTABLE có nghĩa là chúng ta có thể thêm, xóa hoặc cập nhật các phần tử trong từ điển. Dưới đây là một số ví dụ về mã để hiểu rõ hơn về từ điển trong python.

Một điểm quan trọng cần lưu ý là chúng ta không thể sử dụng một đối tượng có thể thay đổi làm khóa trong từ điển. Vì vậy, danh sách không được phép làm khóa trong từ điển.

1. Tạo từ điển

#creating a dictionary
 
my_dict = {
    1:'Delhi',
    2:'Patna',
    3:'Bangalore'
}
print(my_dict)

Đầu ra

{1: 'Delhi', 2: 'Patna', 3: 'Bangalore'}

Ở đây, số nguyên là khóa của từ điển và tên thành phố được kết hợp với số nguyên là giá trị của từ điển.

2. Truy cập các mục từ Từ điển

#access an item
 
print(my_dict[1])

Đầu ra

'Delhi'

3. Độ dài của từ điển

#length of the dictionary
 
len(my_dict)

Đầu ra

3

4. Sắp xếp từ điển

#sorting based on the key 
 
Print(sorted(my_dict.items()))
 
 
#sorting based on the values of dictionary
 
print(sorted(my_dict.values()))

Đầu ra

[(1, 'Delhi'), (2, 'Bangalore'), (3, 'Patna')]
 
['Bangalore', 'Delhi', 'Patna']

5. Thêm các phần tử trong Từ điển

#adding a new item in dictionary 
 
my_dict[4] = 'Lucknow'
print(my_dict)

Đầu ra

{1: 'Delhi', 2: 'Patna', 3: 'Bangalore', 4: 'Lucknow'}

6. Xóa các phần tử khỏi Từ điển

#for deleting an item from dict using the specific key
 
my_dict.pop(4)
print(my_dict)
 
#for deleting last item from the list
 
my_dict.popitem()
 
#for clearing the dictionary
 
my_dict.clear()
print(my_dict)

Đầu ra

{1: 'Delhi', 2: 'Patna', 3: 'Bangalore'}
(3, 'Bangalore')
{}

BỘ

Set là một kiểu dữ liệu khác trong python là một tập hợp không có thứ tự không có phần tử trùng lặp. Các trường hợp sử dụng phổ biến cho một tập hợp là loại bỏ các giá trị trùng lặp và thực hiện kiểm tra tư cách thành viên. Các dấu ngoặc nhọn hoặc set()hàm có thể được sử dụng để tạo bộ. Một điều cần lưu ý là trong khi tạo một tập hợp trống, chúng ta phải sử set()dụng. Sau đó tạo ra một từ điển trống. not { }

Dưới đây là một số ví dụ mã để hiểu rõ hơn về các bộ trong python.

1. Tạo một Tập hợp

#creating set
 
my_set = {"apple", "mango", "strawberry", "apple"}
print(my_set)

Đầu ra

{'apple', 'strawberry', 'mango'}

2. Truy cập các mục từ một Bộ

#to test for an element inside the set
 
"apple" in my_set

Đầu ra

True

3. Chiều dài của một bộ

print(len(my_set))

Đầu ra

3

4. Sắp xếp một tập hợp

print(sorted(my_set))

Đầu ra

['apple', 'mango', 'strawberry']

5. Thêm các phần tử trong Set

my_set.add("guava")
print(my_set)

Đầu ra

{'apple', 'guava', 'mango', 'strawberry'}

6. Xóa các phần tử khỏi Set

my_set.remove("mango")
print(my_set)

Đầu ra

{'apple', 'guava', 'strawberry'}

Sự kết luận

Trong bài viết này, chúng ta đã xem qua các cấu trúc dữ liệu được sử dụng phổ biến nhất trong python và cũng đã xem các phương thức khác nhau được liên kết với chúng.

Liên kết: https://www.askpython.com/python/data

#python #datastructures

Thierry  Perret

Thierry Perret

1662365538

Les Structures De Données Les Plus Couramment Utilisées En Python

Dans tout langage de programmation, nous devons traiter des données. Maintenant, l'une des choses les plus fondamentales dont nous avons besoin pour travailler avec les données est de les stocker, de les gérer et d'y accéder efficacement de manière organisée afin qu'elles puissent être utilisées chaque fois que cela est nécessaire pour nos besoins. Les structures de données sont utilisées pour répondre à tous nos besoins.

Que sont les Structures de Données ?

Les structures de données sont les blocs de construction fondamentaux d'un langage de programmation. Il vise à fournir une approche systématique pour répondre à toutes les exigences mentionnées précédemment dans l'article. Les structures de données en Python sont List, Tuple, Dictionary et Set . Ils sont considérés comme des structures de données implicites ou intégrées dans Python . Nous pouvons utiliser ces structures de données et leur appliquer de nombreuses méthodes pour gérer, relier, manipuler et utiliser nos données.

Nous avons également des structures de données personnalisées définies par l'utilisateur, à savoir Stack , Queue , Tree , Linked List et Graph . Ils permettent aux utilisateurs d'avoir un contrôle total sur leurs fonctionnalités et de les utiliser à des fins de programmation avancées. Cependant, nous nous concentrerons sur les structures de données intégrées pour cet article.

Structures de données implicites Python

Structures de données implicites Python

LISTE

Les listes nous aident à stocker nos données de manière séquentielle avec plusieurs types de données. Ils sont comparables aux tableaux à l'exception qu'ils peuvent stocker différents types de données comme des chaînes et des nombres en même temps. Chaque élément ou élément d'une liste a un index attribué. Étant donné que Python utilise l' indexation basée sur 0 , le premier élément a un index de 0 et le comptage continue. Le dernier élément d'une liste commence par -1 qui peut être utilisé pour accéder aux éléments du dernier au premier. Pour créer une liste, nous devons écrire les éléments à l'intérieur des crochets .

L'une des choses les plus importantes à retenir à propos des listes est qu'elles sont Mutable . Cela signifie simplement que nous pouvons modifier un élément dans une liste en y accédant directement dans le cadre de l'instruction d'affectation à l'aide de l'opérateur d'indexation. Nous pouvons également effectuer des opérations sur notre liste pour obtenir la sortie souhaitée. Passons en revue le code pour mieux comprendre les opérations de liste et de liste.

1. Créer une liste

#creating the list
my_list = ['p', 'r', 'o', 'b', 'e']
print(my_list)

Production

['p', 'r', 'o', 'b', 'e']

2. Accéder aux éléments de la liste

#accessing the list 
 
#accessing the first item of the list
my_list[0]

Production

'p'
#accessing the third item of the list
my_list[2]
'o'

3. Ajouter de nouveaux éléments à la liste

#adding item to the list
my_list + ['k']

Production

['p', 'r', 'o', 'b', 'e', 'k']

4. Suppression d'éléments

#removing item from the list
#Method 1:
 
#Deleting list items
my_list = ['p', 'r', 'o', 'b', 'l', 'e', 'm']
 
# delete one item
del my_list[2]
 
print(my_list)
 
# delete multiple items
del my_list[1:5]
 
print(my_list)

Production

['p', 'r', 'b', 'l', 'e', 'm']
['p', 'm']
#Method 2:
 
#with remove fucntion
my_list = ['p','r','o','k','l','y','m']
my_list.remove('p')
 
 
print(my_list)
 
#Method 3:
 
#with pop function
print(my_list.pop(1))
 
# Output: ['r', 'k', 'l', 'y', 'm']
print(my_list)

Production

['r', 'o', 'k', 'l', 'y', 'm']
o
['r', 'k', 'l', 'y', 'm']

5. Liste de tri

#sorting of list in ascending order
 
my_list.sort()
print(my_list)

Production

['k', 'l', 'm', 'r', 'y']
#sorting of list in descending order
 
my_list.sort(reverse=True)
print(my_list)

Production

['y', 'r', 'm', 'l', 'k']

6. Trouver la longueur d'une liste

#finding the length of list
 
len(my_list)

Production

5

TUPLE

Les tuples sont très similaires aux listes avec une différence clé qu'un tuple est IMMUTABLE , contrairement à une liste. Une fois que nous avons créé un tuple ou que nous avons un tuple, nous ne sommes pas autorisés à modifier les éléments qu'il contient. Cependant, si nous avons un élément à l'intérieur d'un tuple, qui est une liste elle-même, alors seulement nous pouvons accéder ou changer dans cette liste. Pour créer un tuple, nous devons écrire les éléments entre parenthèses . Comme les listes, nous avons des méthodes similaires qui peuvent être utilisées avec des tuples. Passons en revue quelques extraits de code pour comprendre l'utilisation des tuples.

1. Créer un tuple

#creating of tuple
 
my_tuple = ("apple", "banana", "guava")
print(my_tuple)

Production

('apple', 'banana', 'guava')

2. Accéder aux éléments d'un Tuple

#accessing first element in tuple
 
my_tuple[1]

Production

'banana'

3. Longueur d'un tuple

#for finding the lenght of tuple
 
len(my_tuple)

Production

3

4. Conversion d'un tuple en liste

#converting tuple into a list
 
my_tuple_list = list(my_tuple)
type(my_tuple_list)

Production

list

5. Inverser un tuple

#Reversing a tuple
 
tuple(sorted(my_tuple, reverse=True)) 

Production

('guava', 'banana', 'apple')

6. Trier un tuple

#sorting tuple in ascending order
 
tuple(sorted(my_tuple)) 

Production

('apple', 'banana', 'guava')

7. Supprimer des éléments de Tuple

Pour supprimer des éléments du tuple, nous avons d'abord converti le tuple en une liste comme nous l'avons fait dans l'une de nos méthodes ci-dessus (point n ° 4), puis avons suivi le même processus de la liste et avons explicitement supprimé un tuple entier, juste en utilisant le del déclaration .

DICTIONNAIRE

Dictionary est une collection, ce qui signifie simplement qu'il est utilisé pour stocker une valeur avec une clé et extraire la valeur donnée à la clé. Nous pouvons le considérer comme un ensemble de clés : des paires de valeurs et chaque clé d'un dictionnaire est supposée être unique afin que nous puissions accéder aux valeurs correspondantes en conséquence.

Un dictionnaire est indiqué par l'utilisation d' accolades { } contenant les paires clé : valeur. Chacune des paires d'un dictionnaire est séparée par des virgules. Les éléments d'un dictionnaire ne sont pas ordonnés , la séquence n'a pas d'importance pendant que nous y accédons ou que nous les stockons.

Ils sont MUTABLES ce qui signifie que nous pouvons ajouter, supprimer ou mettre à jour des éléments dans un dictionnaire. Voici quelques exemples de code pour mieux comprendre un dictionnaire en python.

Un point important à noter est que nous ne pouvons pas utiliser un objet mutable comme clé dans le dictionnaire. Ainsi, une liste n'est pas autorisée comme clé dans le dictionnaire.

1. Création d'un dictionnaire

#creating a dictionary
 
my_dict = {
    1:'Delhi',
    2:'Patna',
    3:'Bangalore'
}
print(my_dict)

Production

{1: 'Delhi', 2: 'Patna', 3: 'Bangalore'}

Ici, les entiers sont les clés du dictionnaire et le nom de ville associé aux entiers sont les valeurs du dictionnaire.

2. Accéder aux éléments d'un dictionnaire

#access an item
 
print(my_dict[1])

Production

'Delhi'

3. Longueur d'un dictionnaire

#length of the dictionary
 
len(my_dict)

Production

3

4. Trier un dictionnaire

#sorting based on the key 
 
Print(sorted(my_dict.items()))
 
 
#sorting based on the values of dictionary
 
print(sorted(my_dict.values()))

Production

[(1, 'Delhi'), (2, 'Bangalore'), (3, 'Patna')]
 
['Bangalore', 'Delhi', 'Patna']

5. Ajout d'éléments dans le dictionnaire

#adding a new item in dictionary 
 
my_dict[4] = 'Lucknow'
print(my_dict)

Production

{1: 'Delhi', 2: 'Patna', 3: 'Bangalore', 4: 'Lucknow'}

6. Suppression d'éléments du dictionnaire

#for deleting an item from dict using the specific key
 
my_dict.pop(4)
print(my_dict)
 
#for deleting last item from the list
 
my_dict.popitem()
 
#for clearing the dictionary
 
my_dict.clear()
print(my_dict)

Production

{1: 'Delhi', 2: 'Patna', 3: 'Bangalore'}
(3, 'Bangalore')
{}

POSITIONNER

Set est un autre type de données en python qui est une collection non ordonnée sans éléments en double. Les cas d'utilisation courants d'un ensemble consistent à supprimer les valeurs en double et à effectuer des tests d'appartenance. Les accolades ou la set()fonction peuvent être utilisées pour créer des ensembles. Une chose à garder à l'esprit est que lors de la création d'un ensemble vide, nous devons utiliser set(), et . Ce dernier crée un dictionnaire vide. not { }

Voici quelques exemples de code pour mieux comprendre les ensembles en python.

1. Créer un ensemble

#creating set
 
my_set = {"apple", "mango", "strawberry", "apple"}
print(my_set)

Production

{'apple', 'strawberry', 'mango'}

2. Accéder aux éléments d'un ensemble

#to test for an element inside the set
 
"apple" in my_set

Production

True

3. Longueur d'un ensemble

print(len(my_set))

Production

3

4. Trier un ensemble

print(sorted(my_set))

Production

['apple', 'mango', 'strawberry']

5. Ajout d'éléments dans Set

my_set.add("guava")
print(my_set)

Production

{'apple', 'guava', 'mango', 'strawberry'}

6. Suppression d'éléments de Set

my_set.remove("mango")
print(my_set)

Production

{'apple', 'guava', 'strawberry'}

Conclusion

Dans cet article, nous avons passé en revue les structures de données les plus couramment utilisées en python et avons également vu diverses méthodes qui leur sont associées.

Lien : https://www.askpython.com/python/data

#python #datastructures

田辺  亮介

田辺 亮介

1662351030

Python中最常用的數據結構

在任何編程語言中,我們都需要處理數據。現在,我們需要處理數據的最基本的事情之一就是以有組織的方式有效地存儲、管理和訪問它,以便我們可以在需要時將其用於我們的目的。數據結構用於滿足我們所有的需求。

什麼是數據結構?

數據結構是編程語言的基本構建塊。它旨在提供一種系統的方法來滿足本文前面提到的所有要求。Python 中的數據結構是List、Tuple、Dictionary 和 Set。它們被視為Python 中的隱式或內置數據結構。我們可以使用這些數據結構並對它們應用多種方法來管理、關聯、操作和利用我們的數據。

我們還有用戶定義的自定義數據結構,即StackQueueTreeLinked ListGraph。它們允許用戶完全控制其功能並將其用於高級編程目的。但是,我們將專注於本文的內置數據結構。

隱式數據結構 Python

隱式數據結構 Python

列表

列表幫助我們以多種數據類型順序存儲數據。它們類似於數組,除了它們可以同時存儲不同的數據類型,如字符串和數字。列表中的每個項目或元素都有一個指定的索引。由於Python 使用基於 0 的索引,因此第一個元素的索引為 0,並且繼續計數。列表的最後一個元素以 -1 開頭,可用於訪問從最後一個到第一個的元素。要創建一個列表,我們必須將項目寫在方括號內

關於列表要記住的最重要的事情之一是它們是可變的。這僅僅意味著我們可以通過使用索引運算符直接訪問它作為賦值語句的一部分來更改列表中的元素。我們還可以對列表執行操作以獲得所需的輸出。讓我們通過代碼來更好地理解列表和列表操作。

1. 創建列表

#creating the list
my_list = ['p', 'r', 'o', 'b', 'e']
print(my_list)

輸出

['p', 'r', 'o', 'b', 'e']

2. 訪問列表中的項目

#accessing the list 
 
#accessing the first item of the list
my_list[0]

輸出

'p'
#accessing the third item of the list
my_list[2]
'o'

3. 向列表中添加新項目

#adding item to the list
my_list + ['k']

輸出

['p', 'r', 'o', 'b', 'e', 'k']

4. 移除物品

#removing item from the list
#Method 1:
 
#Deleting list items
my_list = ['p', 'r', 'o', 'b', 'l', 'e', 'm']
 
# delete one item
del my_list[2]
 
print(my_list)
 
# delete multiple items
del my_list[1:5]
 
print(my_list)

輸出

['p', 'r', 'b', 'l', 'e', 'm']
['p', 'm']
#Method 2:
 
#with remove fucntion
my_list = ['p','r','o','k','l','y','m']
my_list.remove('p')
 
 
print(my_list)
 
#Method 3:
 
#with pop function
print(my_list.pop(1))
 
# Output: ['r', 'k', 'l', 'y', 'm']
print(my_list)

輸出

['r', 'o', 'k', 'l', 'y', 'm']
o
['r', 'k', 'l', 'y', 'm']

5.排序列表

#sorting of list in ascending order
 
my_list.sort()
print(my_list)

輸出

['k', 'l', 'm', 'r', 'y']
#sorting of list in descending order
 
my_list.sort(reverse=True)
print(my_list)

輸出

['y', 'r', 'm', 'l', 'k']

6. 查找列表的長度

#finding the length of list
 
len(my_list)

輸出

5

元組

元組與列表非常相似,關鍵區別在於元組是 IMMUTABLE,與列表不同。一旦我們創建了一個元組或有一個元組,我們就不能改變它裡面的元素。但是,如果我們在元組中有一個元素,它本身就是一個列表,那麼我們只能在該列表中訪問或更改。要創建一個元組,我們必須在括號內寫入項目。像列表一樣,我們有類似的方法可以用於元組。讓我們通過一些代碼片段來理解使用元組。

1. 創建一個元組

#creating of tuple
 
my_tuple = ("apple", "banana", "guava")
print(my_tuple)

輸出

('apple', 'banana', 'guava')

2. 從元組訪問項目

#accessing first element in tuple
 
my_tuple[1]

輸出

'banana'

3. 元組的長度

#for finding the lenght of tuple
 
len(my_tuple)

輸出

3

4. 將元組轉換為列表

#converting tuple into a list
 
my_tuple_list = list(my_tuple)
type(my_tuple_list)

輸出

list

5. 反轉元組

#Reversing a tuple
 
tuple(sorted(my_tuple, reverse=True)) 

輸出

('guava', 'banana', 'apple')

6. 對元組進行排序

#sorting tuple in ascending order
 
tuple(sorted(my_tuple)) 

輸出

('apple', 'banana', 'guava')

7. 從元組中刪除元素

為了從元組中刪除元素,我們首先將元組轉換為列表,就像我們在上面的方法之一(第 4 點)中所做的那樣,然後遵循列表的相同過程,並顯式刪除整個元組,只需使用del聲明

字典

字典是一個集合,它只是意味著它用於存儲帶有某個鍵的值並提取給定鍵的值。我們可以將其視為一組鍵:值對 和字典中的每個都應該是唯一的,以便我們可以相應地訪問相應的

字典由包含鍵:值對的花括號 { }表示。字典中的每一對都以逗號分隔。字典中的元素是無序的,當我們訪問或存儲它們時,序列並不重要。

它們是可變的,這意味著我們可以在字典中添加、刪除或更新元素。以下是一些代碼示例,可以更好地理解 python 中的字典。

需要注意的重要一點是,我們不能將可變對像用作字典中的鍵。因此,列表不允許作為字典中的鍵。

1. 創建字典

#creating a dictionary
 
my_dict = {
    1:'Delhi',
    2:'Patna',
    3:'Bangalore'
}
print(my_dict)

輸出

{1: 'Delhi', 2: 'Patna', 3: 'Bangalore'}

這裡,整數是字典的鍵,與整數相關的城市名稱是字典的值。

2. 從字典中訪問項目

#access an item
 
print(my_dict[1])

輸出

'Delhi'

3. 字典的長度

#length of the dictionary
 
len(my_dict)

輸出

3

4. 對字典進行排序

#sorting based on the key 
 
Print(sorted(my_dict.items()))
 
 
#sorting based on the values of dictionary
 
print(sorted(my_dict.values()))

輸出

[(1, 'Delhi'), (2, 'Bangalore'), (3, 'Patna')]
 
['Bangalore', 'Delhi', 'Patna']

5. 在字典中添加元素

#adding a new item in dictionary 
 
my_dict[4] = 'Lucknow'
print(my_dict)

輸出

{1: 'Delhi', 2: 'Patna', 3: 'Bangalore', 4: 'Lucknow'}

6.從字典中刪除元素

#for deleting an item from dict using the specific key
 
my_dict.pop(4)
print(my_dict)
 
#for deleting last item from the list
 
my_dict.popitem()
 
#for clearing the dictionary
 
my_dict.clear()
print(my_dict)

輸出

{1: 'Delhi', 2: 'Patna', 3: 'Bangalore'}
(3, 'Bangalore')
{}

Set 是 python 中的另一種數據類型,它是一個沒有重複元素的無序集合。集合的常見用例是刪除重複值並執行成員資格測試。花括號set()函數可用於創建集合。要記住的一件事是,在創建空集時,我們必須使用set(),。後者創建一個空字典。 not { }

以下是一些代碼示例,可幫助您更好地理解 Python 中的集合。

1. 創建一個 集合

#creating set
 
my_set = {"apple", "mango", "strawberry", "apple"}
print(my_set)

輸出

{'apple', 'strawberry', 'mango'}

2. 訪問集合中的項目

#to test for an element inside the set
 
"apple" in my_set

輸出

True

3. 集合的長度

print(len(my_set))

輸出

3

4. 對集合進行排序

print(sorted(my_set))

輸出

['apple', 'mango', 'strawberry']

5. 在Set中添加元素

my_set.add("guava")
print(my_set)

輸出

{'apple', 'guava', 'mango', 'strawberry'}

6. 從 Set 中移除元素

my_set.remove("mango")
print(my_set)

輸出

{'apple', 'guava', 'strawberry'}

結論

在本文中,我們瀏覽了 Python 中最常用的數據結構,並了解了與它們相關的各種方法。

鏈接:https ://www.askpython.com/python/data

#python #datastructures