0% found this document useful (0 votes)
5 views1 page

Comparison of Python Data Structure Methods

The document provides a comparison of methods applicable to lists, strings, tuples, and dictionaries in Python. It details various operations such as adding, removing, and manipulating elements, along with their input types and descriptions. Each method is marked to indicate which data types it applies to, highlighting the differences in functionality across these data structures.

Uploaded by

carifor770
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Comparison of Python Data Structure Methods

The document provides a comparison of methods applicable to lists, strings, tuples, and dictionaries in Python. It details various operations such as adding, removing, and manipulating elements, along with their input types and descriptions. Each method is marked to indicate which data types it applies to, highlighting the differences in functionality across these data structures.

Uploaded by

carifor770
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Comparison of Methods for List, String, Tuple, and

Dictionary
Method List String Tuple Dictionary Input Type Description
append() ✔ - - - value Adds element at the end of list

extend() ✔ - - - iterable Appends elements from another iterable

insert() ✔ - - - index, value Inserts element at given index

remove() ✔ - - - value Removes first occurrence of element

pop() ✔ - - ✔ index (optional for list), key(for dict) Removes element at index (list) or key (dict)

clear() ✔ - - ✔ none Removes all elements

index() ✔ ✔ ✔ - value Returns index of first occurrence

count() ✔ ✔ ✔ - value Counts number of occurrences

sort() ✔ - - - none or key function Sorts list in ascending order

reverse() ✔ - - - none Reverses list in place

copy() ✔ - - ✔ none Returns shallow copy

get() - - - ✔ key Returns value for key, or None

keys() - - - ✔ none Returns all keys

values() - - - ✔ none Returns all values

items() - - - ✔ none Returns key-value pairs

update() - - - ✔ dict or iterable Updates dictionary with given pairs

fromkeys() - - - ✔ keys, value(optional) Creates new dict with given keys

join() - ✔ - - iterable of strings Concatenates iterable with separator

split() - ✔ - - separator(optional) Splits string into list

strip() - ✔ - - chars(optional) Removes leading/trailing characters

replace() - ✔ - - old, new Replaces substring with another

upper() - ✔ - - none Converts to uppercase

lower() - ✔ - - none Converts to lowercase

startswith() - ✔ - - prefix Checks if string starts with prefix

endswith() - ✔ - - suffix Checks if string ends with suffix

find() - ✔ - - substring Returns lowest index of substring

rfind() - ✔ - - substring Returns highest index of substring

You might also like