Tuesday, July 19, 2022

Oxford English dictionary (OED) adds 200 east African words - Quartz Africa - Dictionary

The Oxford English Dictionary (OED)—the largest dictionary of the English language—has added 200 new and revised entries from East African English, which are primarily used in Kenya, Tanzania, and Uganda.

In a statement, the OED said coverage of east African English includes the varieties of English spoken in Kenya, Tanzania, and Uganda, three countries that share a common Anglophone background despite their different colonial histories.

The words span from popular street snacks to musical genres in the region.

East African English is influencing the language globally

Nyama choma, which is a favorite across Tanzania and Kenya’s entertainment spots, is meat roasted over an open fire. While chips mayai can be found in any local restaurant in Tanzania and is a mix of omelette and chips. Katogo is a Ugandan breakfast dish using banana.

Local terms for shopping are also included. Mama ntilie, which is a slang term used in Tanzania to describe female vendors who sell street food along the roadside, has been added, along with duka—a local shop selling everything from toiletries to soft drinks.

With the global rise of afrobeats, it’s no wonder that ‘Bongo Flava’ now features in the dictionary. This is a type of music originating from Tanzania and made famous by the country’s biggest artist, Diamond Platnumz.

Daladala—buses which are used across East Africa—is also a new entry. The word comes from ‘dollar’, which is what bus conductors called out as people boarded, and was recreated to ‘daladala.’

Sayings and greetings, which form an important part of east African culture, have been incorporated. While in English, it is typical to say ‘long time no see’ after some time has passed, in Uganda, it is common to say ‘you are lost’, while ‘Well done!’ can also be used as a greeting, particularly when someone is at work.

Swahili language is a huge influence in east Africa

“East Africa has ‘altered (English) to suit its new African surroundings’—to cite Chinua Achebe who was referring to his experience,” said Dr Ida Hadjivayanis, Senior Swahili lecturer at the School of Oriental and African Studies (SOAS).

“I see the language change in my work where through assessing international Swahili exams, I find candidates using the bantu structure with English words, for example ‘kupay’ as opposed to ‘to pay’.”

“This stems from the code switching that is rooted in our experience of living with both Kiswahili and English as well as integrating English into the east African milieu. Hence, greeting someone with ‘umepotea’—‘you are lost’ is common and simply means ‘long time no see’.”

Sheng—Kenya’s beloved urban slang—has also become a popular dialect in the country, mixing English and Swahili, as well as other languages.

“Adopting words of another language is a normal process in the growth and development of  languages,” said Chege Githiora, Professor of Linguistics at Kenyatta University. “In this case, it is a recognition by English of the growing prestige of Swahili as a global language, and the east African culture it embodies.”

“Similarly, English and Arabic (and others) have enriched Swahili which has adopted many words and expressions over the centuries.”

Adblock test (Why?)

Python Dictionary: Zero to Hero with Examples | by Amit Chauhan | Jul, 2022 - Medium - Dictionary

Learning dictionary for data science and machine learning applications

Photo by Alex Chumak on Unsplash

Introduction

Python scripts or programs are generally impossible to exist without the use of lists and dictionaries. As we know, dictionaries play a huge role in indexing; we all have already been familiar with the basic concept of Dictionaries from the previous articles. But in this article, we’ll be exploring advanced methods like turning a dictionary into a list or two lists with real-life examples. So let’s have a recap…

What is a Dictionary?

Theoretically, a dictionary is to store data in key-value pairs. And these items are accessed using keys and not their positions, unlike lists. The values in a dictionary can be of any type (string, integers, floating-point numbers, etc.).

Syntax:

A dictionary is defined by an enclosed comma-separated list of key-value pairs in curly braces.

D = {(key):(value),(key):(value),(key):(value),(key):(value)}

Example:

Let’s look at an example of student roll numbers. Consider a dictionary with students’ roll numbers and their names. Practically, there might be many students with the same names. Hence it would be very difficult to get the details. This is where the concept of dictionaries can help us. Each name is stored under a number. So when we search for a number, we get all the details of one student without any mess. You can also enter a new record into a dictionary very easily.

Program Example:

#searching for recordsSearch_no = {45:’Meena’, 56:’Raj’, 3:’Ashley’, 6:’Balu’, 20:’Hari’}print(Search_no[3])
print(Search_no[45])
print(Search_no[20])
Output:
Ashley
Meena
Hari
#entering a new recordSearch_no = {45:’Meena’, 56:’Raj’, 3:’Ashley’, 6:’Balu’, 20:’Hari’}Search_no[1] = “Ashi”
print(Search_no)
Output:{45: ‘Meena’, 56: ‘Raj’, 3: ‘Ashley’, 6: ‘Balu’, 20: ‘Hari’, 1: ‘Ashi’}

Operators in dictionary

Let us now have a look at some of the operators used in Dictionaries.

  • len(D): The len() operator is to return the number of entries stored in the dictionary. In simple words, to get the number of key-value pairs.

Program:

Search_no = {45:’Meena’, 56:’Raj’, 3:’Ashley’, 6:’Balu’, 20:’Hari’, 77:’Priya’, 78:’Shankar’, 2:’Adhil’}print(len(Search_no))Output:8
  • del D[k]: The ‘del D[k]’ operator is to delete the key along with its value.
Program:Search_no = {45:’Meena’, 56:’Raj’, 3:’Ashley’, 6:’Balu’, 20:’Hari’, 77:’Priya’, 78:’Shankar’, 2:’Adhil’}del Search_no[2]print(Search_no)Output:{45: ‘Meena’, 56: ‘Raj’, 3: ‘Ashley’, 6: ‘Balu’, 20: ‘Hari’, 77: ‘Priya’, 78: ‘Shankar’}
  • k in D: The ‘k in D’ operator is similar to a true/false statement. If the Key exists then it will return true.
Program:Search_no = {45:’Meena’, 56:’Raj’, 3:’Ashley’, 6:’Balu’, 20:’Hari’, 77:’Priya’, 78:’Shankar’, 2:’Adhil’}print(45 in Search_no)
print(49 in Search_no)
Output:
True
False
  • k not in D: The ‘k not in D’ operator is similar to a true/false statement. If the key doesn’t exist, it returns the output as false.
Program:Search_no = {45:’Meena’, 56:’Raj’, 3:’Ashley’, 6:’Balu’, 20:’Hari’, 77:’Priya’, 78:’Shankar’, 2:’Adhil’}print(3 not in Search_no)
print(49 not in Search_no)
Output:
False
True

Important methods in a dictionary

  • Pop and popitem()

pop():

We do know that the pop() method is used to take away a specific element in a list. This method can also be applied to dictionaries. But the difference is that lists are ordered, whereas dictionaries are unordered. Hence pop() will act differently in dictionaries. You can remove a key-value pair by specifying the key in the pop() argument.

Note: KeyError will be raised when the key is not found.

Program:#1Search_no = {45:’Meena’, 56:’Raj’, 3:’Ashley’, 6:’Balu’, 20:’Hari’, 77:’Priya’, 78:’Shankar’, 2:’Adhil’}search = Search_no.pop(2)
print(Search_no)
Output:
{45: ‘Meena’, 56: ‘Raj’, 3: ‘Ashley’, 6: ‘Balu’, 20: ‘Hari’, 77: ‘Priya’, 78: ‘Shankar’}
#2Search_no = {45:’Meena’, 56:’Raj’, 3:’Ashley’, 6:’Balu’, 20:’Hari’, 77:’Priya’, 78:’Shankar’}search = Search_no.pop(4)
print(search)
Output:
search = Search_no.pop(4)
KeyError: 4

popitem():

Compared to pop(), popitem() is a little different. This method does not take any argument. But once this method is executed, it removes the last key-value pair present in the dictionary.

Note: KeyError will be raised if popitem() is applied to an empty dictionary.

Program:#1Search_no = {45:’Meena’, 56:’Raj’, 3:’Ashley’,
6:’Balu’, 20:’Hari’, 77:’Priya’,
78:’Shankar’}
(roll_no, name)= Search_no.popitem()
print(roll_no, name)
Output:
78 Shankar
#2Search_no = {}(roll_no, name)= Search_no.popitem()
print(roll_no, name)
Output:
(roll_no, name)= Search_no.popitem()
KeyError: ‘popitem(): dictionary is empty’

Accessing non-existing keys

In dictionaries, it is evident from the above examples that when we access an element that doesn’t exist, the program would throw an error. Now, this can be prevented easily by using the ‘in’ operator. Let’s see how:

Program:Search_no = {45:’Meena’, 56:’Raj’, 3:’Ashley’,
6:’Balu’, 20:’Hari’, 77:’Priya’,
78:’Shankar’}
no = 49if no in Search_no:
print(Search_no[no])
else:
print(no, “is not in the dictionary”)
Output:
49 is not in the dictionary

Explanation:

In this program, we are using the if-else condition along with the ‘in’ operator to access elements. If the element we are searching for is present, it will execute the first statement, or else, it will pass the second statement.

Tkinter: Basic GUI Widgets Elements with Python Example

Graphical user interface with tkinker python library

amitprius.medium.com

Numpy Vectorization for Faster Operations With Python

A small comparison of codes between regular and Numpy codes

amitprius.medium.com

copy()

The copy() method is to create a copy of the existing dictionary. This is very handy when you want to play around with the data or make any minor changes to the duplicated dictionary without actually losing or creating the existing dictionary.

Program:Search_no = {45:’Meena’, 56:’Raj’, 3:’Ashley’, 6:’Balu’}s_no = Search_no.copy()Search_no[45]= “Sheena”
print(s_no)
print(Search_no)
Output:
{45: ‘Meena’, 56: ‘Raj’, 3: ‘Ashley’, 6: ‘Balu’}
{45: ‘Sheena’, 56: ‘Raj’, 3: ‘Ashley’, 6: ‘Balu’}

Explanation:

The above program shows us how to make a copy of a dictionary by changing one of the values.

Now, the problem with this copy() method is that it’s a shallow copy. If the value in a dictionary is complex like lists, then the in-places changes in this object and can also affect the copy as well. Let’s look at an example:

Program 1:Students = { “Meena”:{“Subject”:”English”, “Marks”: 69},
“Raj”:{“Subject”:”Maths”, “Marks”: 80},
“Sharon”:{“Subject”:”Science”, “Marks”: 96}}
Students2 = Students.copy()Students[“Meena”][“Marks”] = 98print(Students)
print(Students2)
Output:{‘Meena’: {‘Subject’: ‘English’, ‘Marks’: 98}, ‘Raj’: {‘Subject’: ‘Maths’, ‘Marks’: 80}, ‘Sharon’:{‘Subject’: ‘Science’, ‘Marks’: 96}}{‘Meena’: {‘Subject’: ‘English’, ‘Marks’: 98}, ‘Raj’: {‘Subject’: ‘Maths’, ‘Marks’: 80},‘Sharon’: {‘Subject’: ‘Science’, ‘Marks’: 96}}

Explanation:

What happens here is that, when handling complex dictionaries, the changes made in the original have been reflected in the copy as well. You can see that when one of the values of the original dictionary: “Students”, is changed to 98, the value in the copy has also been updated. Let’s see how to avoid this:

Program 2:Students = { “Meena”:{“Subject”:”English”, “Marks”: 69},
“Raj”:{“Subject”:”Maths”, “Marks”: 80},
“Sharon”:{“Subject”:”Science”, “Marks”: 96}}
Students2 = Students.copy()Students[“Meena”] = {“Subject”:”English”, “Marks”: 98}print(Students)
print(Students2)
Output:{‘Meena’: {‘Subject’: ‘English’, ‘Marks’: 98}, ‘Raj’: {‘Subject’: ‘Maths’, ‘Marks’: 80}, ‘Sharon’: {‘Subject’: ‘Science’, ‘Marks’: 96}}{‘Meena’: {‘Subject’: ‘English’, ‘Marks’: 69}, ‘Raj’: {‘Subject’: ‘Maths’, ‘Marks’: 80}, ‘Sharon’: {‘Subject’: ‘Science’, ‘Marks’: 96}}

Explanation:

To avoid changes being made to the copy, all you have to do is, enter the entire dictionary that you want to make the change. In this case, we are making changes to only the “Meena” dictionary. Hence, assign the updated information of that entire dictionary alone.

clear()

The clear() method is nothing but to clear the content of a dictionary. Using this method will not delete the dictionary but will just set it to an empty dictionary.

Program:Students = { “Meena”:{“Subject”:”English”, “Marks”: 69},
“Raj”:{“Subject”:”Maths”, “Marks”: 80},
“Sharon”:{“Subject”:”Science”, “Marks”: 96}}
Students.clear()
print(Students)
Output:{}

update()

The update() method is to merge two different dictionaries into one. This means it merges the key values of one dictionary into another by overwriting the values of the exact key.

Program:Search_no_1 = {45:’Meena’, 56:’Raj’, 3:’Ashley’, 6:’Balu’}
Search_no_2 = {45:’Alok’, 33:’Shyam’, 5:’Aliya’, 70:’Sho’}
Search_no_1.update(Search_no_2)
print(Search_no_1)
Output:
{45: ‘Alok’, 56: ‘Raj’, 3: ‘Ashley’, 6: ‘Balu’, 33: ‘Shyam’, 5: ‘Aliya’, 70: ‘Sho’}

Explanation:

As you can see, in the above program, we have created 2 separate dictionaries — Search_no_1 and Search_no_2. We are then using the update() method -“Search_no_1.update(Search_no_2)”. This means that all the key-value pairs of the Search_no_2 dictionary get merged into the Search_no_1 dictionary. Also, the key-value “45:’Meena’” gets updated to “45:’Alok’” (highlighted in black).

Iterate over dictionaries

Coming to iteration, there are only two methods you actually need to iterate over a dictionary. Let’s take a look:

key(), value()

Program:

dic = {“x”:56, “y”:22, “z”:50}for key in dic:
print(key)
for value in dic.values():
print(value)
Output:
x
y
z
56
22
50

Explanation:

In the above program, we are using a for loop to iterate all the keys and values in the dictionary. Using the for loop, we are mainly using two methods: key() and value(). The key() method will only return the keys of the dictionary, and the value() method will only return the values of the dictionary.

Connection between lists and dictionaries

As discussed in the beginning, lists and dictionaries are very efficient in Python program. So, once you get familiar with these two concepts, you might have thought about whether you can change lists to dictionaries or dictionaries to lists. The answer is yes! Let’ see:

Turning dictionaries into lists

Converting a dictionary to a list can be done using only three methods:

item(), keys(), values()

Program:

dic = {“x”:56, “y”:22, “z”:50}item_d = dic.items()
items = list(item_d)
print(items)keys_d = dic.keys()
keys = list(keys_d)
print(keys)values_d = dic.values()
values = list(values_d)
print(values)Output:
[(‘x’, 56), (‘y’, 22), (‘z’, 50)]
[‘x’, ‘y’, ‘z’]
[56, 22, 50]

Explanation:

In the above program, we have converted a dictionary into a list in three different ways. The first way: we use the item() method that returns a dictionary’s key-value pair in the form of a tuple. After this, we are using the list() method to convert the created tuple to a list.

The second way is by using the key() method followed by the list(). And the third way is by using the values() method followed by a list().

Turning lists into dictionaries

You saw how to convert a dictionary to a list. Let’s now do the opposite. To convert a list to a dictionary, we use two methods:

dict(), zip()

Program:

li = [“x”, “y”, “z”, “w”]
ti = [“a”, “b”, “c”]
dic = dict(zip(li, ti))
print(dic)
Output:
{‘x’: ‘a’, ‘y’: ‘b’, ‘z’: ‘c’}

Explanation:

Our main goal in this program is to create a dictionary with the key and values from the two lists. So, our first step is to create two lists. After this, we are using the zip() and dict() methods to convert the list to dictionaries. The zip() function is to return a zip object, where the first item, second item, and so on are paired together. The dict() function is a function to create a dictionary. And finally, we are printing the result where we obtain the output as shown.

Conclusion:

In conclusion, this article has covered some of the advanced concepts of Dictionaries. I strongly recommend experimenting with these methods by applying them in real-time projects using python.

I hope you like the article. Reach me on my LinkedIn and twitter.

Recommended Articles

1. 15 Most Usable NumPy Methods with Python
2. NumPy: Linear Algebra on Images
3. Exception Handling Concepts in Python
4. Pandas: Dealing with Categorical Data
5. Hyper-parameters: RandomSeachCV and GridSearchCV in Machine Learning
6. Fully Explained Linear Regression with Python
7. Fully Explained Logistic Regression with Python
8. Data Distribution using Numpy with Python
9. 40 Most Insanely Usable Methods in Python
10. 20 Most Usable Pandas Shortcut Methods in Python

Adblock test (Why?)

Monday, July 18, 2022

Python Dictionary: Zero to Hero with Examples | by Amit Chauhan | Jul, 2022 - Medium - Dictionary

Learning dictionary for data science and machine learning applications

Photo by Alex Chumak on Unsplash

Introduction

Python scripts or programs are generally impossible to exist without the use of lists and dictionaries. As we know, dictionaries play a huge role in indexing; we all have already been familiar with the basic concept of Dictionaries from the previous articles. But in this article, we’ll be exploring advanced methods like turning a dictionary into a list or two lists with real-life examples. So let’s have a recap…

What is a Dictionary?

Theoretically, a dictionary is to store data in key-value pairs. And these items are accessed using keys and not their positions, unlike lists. The values in a dictionary can be of any type (string, integers, floating-point numbers, etc.).

Syntax:

A dictionary is defined by an enclosed comma-separated list of key-value pairs in curly braces.

D = {(key):(value),(key):(value),(key):(value),(key):(value)}

Example:

Let’s look at an example of student roll numbers. Consider a dictionary with students’ roll numbers and their names. Practically, there might be many students with the same names. Hence it would be very difficult to get the details. This is where the concept of dictionaries can help us. Each name is stored under a number. So when we search for a number, we get all the details of one student without any mess. You can also enter a new record into a dictionary very easily.

Program Example:

#searching for recordsSearch_no = {45:’Meena’, 56:’Raj’, 3:’Ashley’, 6:’Balu’, 20:’Hari’}print(Search_no[3])
print(Search_no[45])
print(Search_no[20])
Output:
Ashley
Meena
Hari
#entering a new recordSearch_no = {45:’Meena’, 56:’Raj’, 3:’Ashley’, 6:’Balu’, 20:’Hari’}Search_no[1] = “Ashi”
print(Search_no)
Output:{45: ‘Meena’, 56: ‘Raj’, 3: ‘Ashley’, 6: ‘Balu’, 20: ‘Hari’, 1: ‘Ashi’}

Operators in dictionary

Let us now have a look at some of the operators used in Dictionaries.

  • len(D): The len() operator is to return the number of entries stored in the dictionary. In simple words, to get the number of key-value pairs.

Program:

Search_no = {45:’Meena’, 56:’Raj’, 3:’Ashley’, 6:’Balu’, 20:’Hari’, 77:’Priya’, 78:’Shankar’, 2:’Adhil’}print(len(Search_no))Output:8
  • del D[k]: The ‘del D[k]’ operator is to delete the key along with its value.
Program:Search_no = {45:’Meena’, 56:’Raj’, 3:’Ashley’, 6:’Balu’, 20:’Hari’, 77:’Priya’, 78:’Shankar’, 2:’Adhil’}del Search_no[2]print(Search_no)Output:{45: ‘Meena’, 56: ‘Raj’, 3: ‘Ashley’, 6: ‘Balu’, 20: ‘Hari’, 77: ‘Priya’, 78: ‘Shankar’}
  • k in D: The ‘k in D’ operator is similar to a true/false statement. If the Key exists then it will return true.
Program:Search_no = {45:’Meena’, 56:’Raj’, 3:’Ashley’, 6:’Balu’, 20:’Hari’, 77:’Priya’, 78:’Shankar’, 2:’Adhil’}print(45 in Search_no)
print(49 in Search_no)
Output:
True
False
  • k not in D: The ‘k not in D’ operator is similar to a true/false statement. If the key doesn’t exist, it returns the output as false.
Program:Search_no = {45:’Meena’, 56:’Raj’, 3:’Ashley’, 6:’Balu’, 20:’Hari’, 77:’Priya’, 78:’Shankar’, 2:’Adhil’}print(3 not in Search_no)
print(49 not in Search_no)
Output:
False
True

Important methods in a dictionary

  • Pop and popitem()

pop():

We do know that the pop() method is used to take away a specific element in a list. This method can also be applied to dictionaries. But the difference is that lists are ordered, whereas dictionaries are unordered. Hence pop() will act differently in dictionaries. You can remove a key-value pair by specifying the key in the pop() argument.

Note: KeyError will be raised when the key is not found.

Program:#1Search_no = {45:’Meena’, 56:’Raj’, 3:’Ashley’, 6:’Balu’, 20:’Hari’, 77:’Priya’, 78:’Shankar’, 2:’Adhil’}search = Search_no.pop(2)
print(Search_no)
Output:
{45: ‘Meena’, 56: ‘Raj’, 3: ‘Ashley’, 6: ‘Balu’, 20: ‘Hari’, 77: ‘Priya’, 78: ‘Shankar’}
#2Search_no = {45:’Meena’, 56:’Raj’, 3:’Ashley’, 6:’Balu’, 20:’Hari’, 77:’Priya’, 78:’Shankar’}search = Search_no.pop(4)
print(search)
Output:
search = Search_no.pop(4)
KeyError: 4

popitem():

Compared to pop(), popitem() is a little different. This method does not take any argument. But once this method is executed, it removes the last key-value pair present in the dictionary.

Note: KeyError will be raised if popitem() is applied to an empty dictionary.

Program:#1Search_no = {45:’Meena’, 56:’Raj’, 3:’Ashley’,
6:’Balu’, 20:’Hari’, 77:’Priya’,
78:’Shankar’}
(roll_no, name)= Search_no.popitem()
print(roll_no, name)
Output:
78 Shankar
#2Search_no = {}(roll_no, name)= Search_no.popitem()
print(roll_no, name)
Output:
(roll_no, name)= Search_no.popitem()
KeyError: ‘popitem(): dictionary is empty’

Accessing non-existing keys

In dictionaries, it is evident from the above examples that when we access an element that doesn’t exist, the program would throw an error. Now, this can be prevented easily by using the ‘in’ operator. Let’s see how:

Program:Search_no = {45:’Meena’, 56:’Raj’, 3:’Ashley’,
6:’Balu’, 20:’Hari’, 77:’Priya’,
78:’Shankar’}
no = 49if no in Search_no:
print(Search_no[no])
else:
print(no, “is not in the dictionary”)
Output:
49 is not in the dictionary

Explanation:

In this program, we are using the if-else condition along with the ‘in’ operator to access elements. If the element we are searching for is present, it will execute the first statement, or else, it will pass the second statement.

Tkinter: Basic GUI Widgets Elements with Python Example

Graphical user interface with tkinker python library

amitprius.medium.com

Numpy Vectorization for Faster Operations With Python

A small comparison of codes between regular and Numpy codes

amitprius.medium.com

copy()

The copy() method is to create a copy of the existing dictionary. This is very handy when you want to play around with the data or make any minor changes to the duplicated dictionary without actually losing or creating the existing dictionary.

Program:Search_no = {45:’Meena’, 56:’Raj’, 3:’Ashley’, 6:’Balu’}s_no = Search_no.copy()Search_no[45]= “Sheena”
print(s_no)
print(Search_no)
Output:
{45: ‘Meena’, 56: ‘Raj’, 3: ‘Ashley’, 6: ‘Balu’}
{45: ‘Sheena’, 56: ‘Raj’, 3: ‘Ashley’, 6: ‘Balu’}

Explanation:

The above program shows us how to make a copy of a dictionary by changing one of the values.

Now, the problem with this copy() method is that it’s a shallow copy. If the value in a dictionary is complex like lists, then the in-places changes in this object and can also affect the copy as well. Let’s look at an example:

Program 1:Students = { “Meena”:{“Subject”:”English”, “Marks”: 69},
“Raj”:{“Subject”:”Maths”, “Marks”: 80},
“Sharon”:{“Subject”:”Science”, “Marks”: 96}}
Students2 = Students.copy()Students[“Meena”][“Marks”] = 98print(Students)
print(Students2)
Output:{‘Meena’: {‘Subject’: ‘English’, ‘Marks’: 98}, ‘Raj’: {‘Subject’: ‘Maths’, ‘Marks’: 80}, ‘Sharon’:{‘Subject’: ‘Science’, ‘Marks’: 96}}{‘Meena’: {‘Subject’: ‘English’, ‘Marks’: 98}, ‘Raj’: {‘Subject’: ‘Maths’, ‘Marks’: 80},‘Sharon’: {‘Subject’: ‘Science’, ‘Marks’: 96}}

Explanation:

What happens here is that, when handling complex dictionaries, the changes made in the original have been reflected in the copy as well. You can see that when one of the values of the original dictionary: “Students”, is changed to 98, the value in the copy has also been updated. Let’s see how to avoid this:

Program 2:Students = { “Meena”:{“Subject”:”English”, “Marks”: 69},
“Raj”:{“Subject”:”Maths”, “Marks”: 80},
“Sharon”:{“Subject”:”Science”, “Marks”: 96}}
Students2 = Students.copy()Students[“Meena”] = {“Subject”:”English”, “Marks”: 98}print(Students)
print(Students2)
Output:{‘Meena’: {‘Subject’: ‘English’, ‘Marks’: 98}, ‘Raj’: {‘Subject’: ‘Maths’, ‘Marks’: 80}, ‘Sharon’: {‘Subject’: ‘Science’, ‘Marks’: 96}}{‘Meena’: {‘Subject’: ‘English’, ‘Marks’: 69}, ‘Raj’: {‘Subject’: ‘Maths’, ‘Marks’: 80}, ‘Sharon’: {‘Subject’: ‘Science’, ‘Marks’: 96}}

Explanation:

To avoid changes being made to the copy, all you have to do is, enter the entire dictionary that you want to make the change. In this case, we are making changes to only the “Meena” dictionary. Hence, assign the updated information of that entire dictionary alone.

clear()

The clear() method is nothing but to clear the content of a dictionary. Using this method will not delete the dictionary but will just set it to an empty dictionary.

Program:Students = { “Meena”:{“Subject”:”English”, “Marks”: 69},
“Raj”:{“Subject”:”Maths”, “Marks”: 80},
“Sharon”:{“Subject”:”Science”, “Marks”: 96}}
Students.clear()
print(Students)
Output:{}

update()

The update() method is to merge two different dictionaries into one. This means it merges the key values of one dictionary into another by overwriting the values of the exact key.

Program:Search_no_1 = {45:’Meena’, 56:’Raj’, 3:’Ashley’, 6:’Balu’}
Search_no_2 = {45:’Alok’, 33:’Shyam’, 5:’Aliya’, 70:’Sho’}
Search_no_1.update(Search_no_2)
print(Search_no_1)
Output:
{45: ‘Alok’, 56: ‘Raj’, 3: ‘Ashley’, 6: ‘Balu’, 33: ‘Shyam’, 5: ‘Aliya’, 70: ‘Sho’}

Explanation:

As you can see, in the above program, we have created 2 separate dictionaries — Search_no_1 and Search_no_2. We are then using the update() method -“Search_no_1.update(Search_no_2)”. This means that all the key-value pairs of the Search_no_2 dictionary get merged into the Search_no_1 dictionary. Also, the key-value “45:’Meena’” gets updated to “45:’Alok’” (highlighted in black).

Iterate over dictionaries

Coming to iteration, there are only two methods you actually need to iterate over a dictionary. Let’s take a look:

key(), value()

Program:

dic = {“x”:56, “y”:22, “z”:50}for key in dic:
print(key)
for value in dic.values():
print(value)
Output:
x
y
z
56
22
50

Explanation:

In the above program, we are using a for loop to iterate all the keys and values in the dictionary. Using the for loop, we are mainly using two methods: key() and value(). The key() method will only return the keys of the dictionary, and the value() method will only return the values of the dictionary.

Connection between lists and dictionaries

As discussed in the beginning, lists and dictionaries are very efficient in Python program. So, once you get familiar with these two concepts, you might have thought about whether you can change lists to dictionaries or dictionaries to lists. The answer is yes! Let’ see:

Turning dictionaries into lists

Converting a dictionary to a list can be done using only three methods:

item(), keys(), values()

Program:

dic = {“x”:56, “y”:22, “z”:50}item_d = dic.items()
items = list(item_d)
print(items)keys_d = dic.keys()
keys = list(keys_d)
print(keys)values_d = dic.values()
values = list(values_d)
print(values)Output:
[(‘x’, 56), (‘y’, 22), (‘z’, 50)]
[‘x’, ‘y’, ‘z’]
[56, 22, 50]

Explanation:

In the above program, we have converted a dictionary into a list in three different ways. The first way: we use the item() method that returns a dictionary’s key-value pair in the form of a tuple. After this, we are using the list() method to convert the created tuple to a list.

The second way is by using the key() method followed by the list(). And the third way is by using the values() method followed by a list().

Turning lists into dictionaries

You saw how to convert a dictionary to a list. Let’s now do the opposite. To convert a list to a dictionary, we use two methods:

dict(), zip()

Program:

li = [“x”, “y”, “z”, “w”]
ti = [“a”, “b”, “c”]
dic = dict(zip(li, ti))
print(dic)
Output:
{‘x’: ‘a’, ‘y’: ‘b’, ‘z’: ‘c’}

Explanation:

Our main goal in this program is to create a dictionary with the key and values from the two lists. So, our first step is to create two lists. After this, we are using the zip() and dict() methods to convert the list to dictionaries. The zip() function is to return a zip object, where the first item, second item, and so on are paired together. The dict() function is a function to create a dictionary. And finally, we are printing the result where we obtain the output as shown.

Conclusion:

In conclusion, this article has covered some of the advanced concepts of Dictionaries. I strongly recommend experimenting with these methods by applying them in real-time projects using python.

I hope you like the article. Reach me on my LinkedIn and twitter.

Recommended Articles

1. 15 Most Usable NumPy Methods with Python
2. NumPy: Linear Algebra on Images
3. Exception Handling Concepts in Python
4. Pandas: Dealing with Categorical Data
5. Hyper-parameters: RandomSeachCV and GridSearchCV in Machine Learning
6. Fully Explained Linear Regression with Python
7. Fully Explained Logistic Regression with Python
8. Data Distribution using Numpy with Python
9. 40 Most Insanely Usable Methods in Python
10. 20 Most Usable Pandas Shortcut Methods in Python

Adblock test (Why?)

'Linguistic Legacy': Oxford to Produce African-American English Dictionary to Recognize Black Influence on Language - Atlanta Black Star - Dictionary

The Oxford University Press will publish an African-American English dictionary to highlight enslaved Africans’ contributions to the English language.

A dictionary of African-American English that will shine a light on the history, meaning and significance of African-American language is set to be released in 2025, by Oxford University Press.

The Oxford Dictionary of African American English is a landmark scholarly initiative to document the lexicon of African American English in a dictionary based on historical principles. (Photo: Getty Images/WIN-Initiative/Neleman)

Prominent historian, Henry Louis Gates Jr. is the editor-in-chief of the Oxford Dictionary of African American English, which will be produced from a three-year research project by Oxford English Dictionary and Harvard University’s Hutchins Center for African and African American Research. Gates leads the center.

“Every speaker of American English borrows heavily from words invented by African Americans, whether they know it or not,” Gates said.

African-American English is not to be confused with ebonics, which is slang, according to linguist experts. Instead, Oxford defines it as the variety of English spoken by African Americans with its roots in African languages and Creoles.

Gates said words like “goober,” “gumbo,” and “okra” survived the Middle Passage, and American-Africans also influenced words such as “cool,” “crib,” “diss,” “hip” and “dig.”

But the Oxford Dictionary of African American English will not be like an ordinary reference dictionary where readers look up the meanings of words and their uses. Instead, it will be a historical dictionary, which will provide background on the evolution of the words.

Dozens of reference books documenting African-American English and slang have been published in the past. Jazz bandleader and singer Cab Calloway’s publication, “Cab Calloway’s Hepster’s Dictionary,” is considered the first dictionary written by an African- American, according to Oxford. Some general dictionaries, including the Oxford English Dictionary, contain words mainly used by African-Americans.

Renowned linguist and professor John Baugh told Atlanta Black Star that while the dictionary will focus on the “linguistic legacy” of enslaved Africans, he also hopes it will help eliminate some negative stereotypes about African-American vernacular.

“The most important thing is for this dictionary to provide accurate linguistic information about words that are uniquely aligned with the linguistic contributions and usages by slave descendants,” said Baugh, president of the Linguistic Society of America. “But one of the things that I hope is an outcome of that academic enterprise is that it may further dispel some of the stereotypes.”

Baugh said there’s a false perception that people who speak African-American English are unintelligent, but he pointed out it is a compilation of slave-descended dialects, which resulted from isolation and racism.

“They talk like that because their ancestors were enslaved and not given the same opportunities as everybody else that immigrated to the United States on their own,” said Baugh, who also serves as one of the advisors for the Oxford project.

According to the Trans-Atlantic Slave Trade Database, 388,000 Africans survived the Middle Passage and were sent to North America. The Oxford Dictionary of African American English will also highlight some of the words that originated among enslaved Africans who were shipped to the Caribbean under British rule.

Kelly Elizabeth Wright, an experimental sociolinguist and lexicographer, who often researches issues related to race in the U.S., said while enslaved Africans were forcibly stripped of their native languages, what was left of the dialects evolved as they gained access to material knowledge and school systems.

African-American languages have been the main drivers behind the evolution of American English for over 200 years, Wright said. Black language is also at the forefront of popular culture.

“Our words shape the historical and contemporary lexicons of American fashion, music, culinary exploits, favorite dances, several organized religions and protests,” Wright, a member of the Oxford English Dictionary Researcher’s Advisory Guild, told Atlanta Black Star.

“Our words are taken from our mouths and streets and teens and show up quickly on nonBlack TikToks, TV shows and coffee mugs,” she added, citing references like “Yas, Queen” or It’s the (insert object of admiration) for me.”

As the dictionary will illuminate, African-American languages also strongly influence white standardized spoken English. Still, Wright said while the Oxford project will help fight some negative ideologies and give African-American English institutional recognition, “none of that is needed for African-American languages to be real.”

Adblock test (Why?)

Meghan Markle's anger after unflattering Urban Dictionary definition appears - The Mirror - Dictionary

[unable to retrieve full-text content]

Meghan Markle's anger after unflattering Urban Dictionary definition appears  The Mirror

Meghan Markle's anger after unflattering Urban Dictionary definition appears - The Mirror - Dictionary

[unable to retrieve full-text content]

Meghan Markle's anger after unflattering Urban Dictionary definition appears  The Mirror

Saturday, July 16, 2022

Trunky Juno spaces out on new single "Oxford English Dictionary" - EARMILK - EARMILK - Dictionary

Newcastle native, Trunky Juno has released a head-nod worthy, reclusive summer single, "Oxford English Dictionary." The track comes as Trunky's first material to follow his well-liked EP, Good Dog, which came last September, cementing his slack-rock approach and the wavy psychedelic form of pop that takes him there.

In describing the track, Juno remarked, “I still find it difficult to spell Mississippi, but I did manage to write a fun song. It's a hooky Alt-Pop that will confidently power walk you straight back to the Trunky Superstore for more Trunky." The grunge tinted songwriting accessibly of Weezer and Beck meet the playful, cosmic-mindedness of The Flaming Lips or Mac Demarco in this memorable soundtrack to a pleasant summer evening.

"Oxford English Dictionary," brings the same endearing level of goofiness masking some real sincerity but with maybe his most radio ready sound to date. The clever one liners and personality here remind of a psyched-up Fountains of Wayne. A punchy drum sequence sets the stage for twangy, loose guitar riff. A group of free floating elements are held together by the gravity of Trunky's songwriting identity. songwriting identity. Lines like "Mississippi is a pretty hard word to spell are foiled by the sweet, earnest "I could love you if you let me." Overall, it's a very sweet, personable depiction of allowing vulnerability amidst summer love.

This is, maybe, the greatest time to become a fan of Trunky Juno as he looks towards July 29th's Belladrum Tartan Hearts Festival in Iverness, and his set at Leeds on the 15th of October. Make sure to follow his build up to these big shows and more via the links below.

"Oxford English Dictionary" is available now via Silent Kid Records.

Connect with Trunky Juno: Instagram | Twitter | Website | Spotify | SoundCloud| Bandcamp

Adblock test (Why?)