COMP101 Introduction to Programming 2020-21 Lecture-24 List Manipulation
[Pages:16]COMP101 Introduction to Programming
2020-21
Lecture-24 List Manipulation
1
1
Python: List join() method
? Convert list to a string ? Use the `join()' method ? Syntax:
separator_string.join(list_name)
? separator_string can be any character to separate the words in the string
2
Python: List join
word_list = ["name one", "name two"] print (word_list) ['name one', 'name two']
word_list_string = " ".join(word_list)
print (word_list_string)
name one name two
name one and name two are separated by a space because we specified a space in the separator_string: word_list_string = " " ...
3
Python: List join
word_list = ["name one", "name two"] print (word_list) ['name one', 'name two']
word_list_string = ",".join(word_list)
print (word_list_string)
name one, name two
name one and name two are separated by a comma because we specified a comma in the separator_string: word_list_string = "," ...
4
Python: List join
word_list = ["This", "is", "a", "sentence"] word_list_string = " ".join(word_list) print (word_list_string) This is a sentence
The separator_string here is a space " " ? there is a space between the quotes If we don't physically put a space in it: word_list_string = "".join(word_list) the words (elements) in the list all join up: Thisisasentence
5
Python: List join
word_list = ["This", "is", "a", "sentence"] word_list_string = "*** ".join(word_list) print (word_list_string) This*** is*** a*** sentence
separator_string can be any character
6
Python: List join
word_list = ["This", "is", "a", "sentence"] word_list_string = "\t".join(word_list) print (word_list_string) This is a sentence
Separator puts a tab between each element
7
Python: String split() method
? Convert a string to a list ? split() ? the `split string function'
? is a `string method' to split a given string into a list
string.split(separator)
? The separator defaults to whitespace, or can be user-specified
8
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- lab manual python programming lab 6cs4 23 jnit
- python basics amazon web services inc
- s˝ˆˇ˘ ncert
- python lists university of michigan
- combining latex with python tex users group tug
- data transformation with cheat sheet github
- introduction to programming in python strings university of texas
- programs on list python class room diary
- p r o g r a m m i n g w i t h p y t h o n university of manchester
- programs list for class xii cs
Related searches
- introduction to philosophy lecture notes
- introduction to management lecture notes
- introduction to computers lecture notes
- introduction to java programming pdf
- introduction to java programming and data structures
- introduction to java programming 10th
- introduction to java programming liang
- introduction to java programming ppt
- introduction to java programming liang pdf
- introduction to r programming pdf
- introduction to python programming pdf
- introduction to java programming 10th edition pdf