Working with Lists & Dictionaries in Python
Introduction and working code for List and Dictionary

Search for a command to run...
Introduction and working code for List and Dictionary

No comments yet. Be the first to comment.
Hi, I will add all python projects, blogs, awesome codes here and hey pythoneers you will enjoy for sure.
NumPy is a Python library used for working with arrays. It also has functions for working in domain of linear algebra, fourier transform, and matrices
I had problems like when we switch branches, UI files like drawables, icons, xml files etc gets in android studio and caches and even after doing basic invalidate caches restart etc it didnt worked, so after compiling all steps leds to soltion , here...

In today's discussion, we delve into implementing bottom navigation in Jetpack Compose, which can be particularly challenging when combined with nested navigation. While several methods are available, developers often encounter difficulties with navi...

A Clean Architecture Guide for Building Modern Android Apps

Master NavController, NavHost, and More

Introduction LangChain is an open-source framework for developing applications powered by large language models (LLMs). It provides a high-level API that makes it easy to chain together multiple LLMs, as well as other data sources and tools, to creat...

On this page
Hi, Guys Today we will learn about List and Dictionaries in python.
Python is an interpreted high-level general-purpose programming language. Its design philosophy emphasizes code readability with its use of significant indentation. Its language constructs as well as its object-oriented approach aim to help programmers write clear, logical code for small and large-scale projects.
List is an mutable data type in python, it is kind of array but supports not only homogenous list of datatypes but mixture too.
In List index of first element starts from 0, list is used to store multiple variable in one variable.
ls = [ "Saurabh", " hashnode", "Python", " datatype"]
print(ls)
['Saurabh', ' hashnode', 'Python', ' datatype']
print(ls[2])
'Python'
We can also use negative indexing:
print(ls[-1])
'datatype'
ls=[1,2,3,4,5]
print(ls)
[1, 2, 3, 4, 5]
print(ls[0]) #?-> 1
print(ls[2])
1
3
print(ls[-1])
5
print(len(ls))
5
ls.insert(1,"python")
print(ls)
ls.insert(3,"kotlin")
print(ls)
[1, 'python', 2, 3, 4, 5]
[1, 'python', 2, 'kotlin', 3, 4, 5] ##after adding kotlin
ls.append("gorilla")
print(ls)
[1, 'python', 2, 'kotlin', 3, 4, 5, 'gorilla']
ls.pop()
print(ls)
[1, 'python', 2, 'kotlin', 3, 4, 5]
ls.pop(2)
print(ls)
[1, 'python', 'kotlin', 3, 4, 5]
ls.remove(3)
print(ls)
[1, 'python', 'kotlin',4, 5]
ls.clear()
print(ls)
[]
lt=["hello","dance","sheeran"] #creating a new list lt
print(lt)
print(ls)
ls=[1,2,3,4] #creating new list ls
newls=[ls,lt] # adding list as item to list
print(newls)
['hello', 'dance', 'sheeran'] #lt
[1,2,3,4] #ls
[[1, 2, 3, 4], ['hello', 'dance', 'sheeran']] #newls
Dictionary in Python is an unordered collection of data values, used to store data values like a map, which, unlike other Data Types that hold only a single value as an element, Dictionary holds key:value pair. Key-value is provided in the dictionary to make it more optimized.
The key value are separated by colon ":" and two key-value pair are spearted by ","
dt={"name":"taylor","song":"blank space"}
## Print dictionary
print(dt)
{'name': 'taylor', 'song': 'blank space'}
access -> square bracket and pass key name
print(dt["name"])
print(dt["song"])
taylor
blank space
dt.update({"Age":23})
print(dt)
{'name': 'taylor', 'song': 'blank space', 'Age': 23}
dt.pop("song")
print(dt)
{'name': 'taylor', 'Age': 23}
dt.popitem()
print(dt)
{'name': 'taylor'}
dt.clear()
print(dt)
{}
dt={"name":"taylor","song":"blank space"}
dt.update({"name":"Ed sheeran"})
print(dt)
{'name': 'Ed sheeran', 'song': 'blank space'}
#Print keys
print(dt.keys())
dict_keys(['name', 'song'])
print(dt.values())
dict_values(['Ed sheeran', 'blank space'])
Pythoneers , lets meet in next Pyblog.