1, please use the code to achieve: the use of an underscore each element of the list is stitched into a string, Li = [' Alex ', ' Eric ', ' Rain ']
#!/usr/bin/env python
#-*-Coding:utf-8-*-
Li = [' Alex ', ' Eric ', ' Rain ']
v = ' _ '. Join (LI)
Print (v)
2. Find the elements in the list, remove the spaces for each element, and look for all elements that begin with a or a and end with C.
Li = ["Alec", "Aric", "Alex", "Tony", "Rain"]
Tu = ("Alec", "Aric", "Alex", "Tony", "Rain")
DiC = {' K1 ': ' Alex ', ' K2 ': ' Aric ', ' K3 ': ' Alex ', ' K4 ': ' Tony '}
#!/usr/bin/env python
#-*-Coding:utf-8-*-
Li = ["Alec", "Aric", "Alex", "Tony", "Rain"]
For S in Li:
S = S.strip ()
Prefix_a = S.startswith (' a ')
Prefix_a = S.startswith (' A ')
Suffix_c = S.endswith (' C ')
If Prefix_a or Prefix_a and Suffix_c:
Print (' element to find:%s '% s)
Tu = ("Alec", "Aric", "Alex", "Tony", "Rain")
For S in Tu:
S = S.strip ()
Prefix_a = S.startswith (' a ')
Prefix_a = S.startswith (' A ')
Suffix_c = S.endswith (' C ')
If Prefix_a or Prefix_a and Suffix_c:
Print (' element to find:%s '% s)
DiC = {' K1 ': ' Alex ', ' K2 ': ' Aric ', ' K3 ': ' Alex ', ' K4 ': ' Tony '}
For S in Dic.values ():
S = S.strip ()
Prefix_a = S.startswith (' a ')
Prefix_a = S.startswith (' A ')
Suffix_c = S.endswith (' C ')
If Prefix_a or Prefix_a and Suffix_c:
Print (' element to find:%s '% s)
Http://www.cnblogs.com/lianzibing/p/6105287.html
Python exercises (Basic knowledge Exercises (iii))