Author's brief introduction : Hello, I'm honker707, You can call me honker, Nova project Season 3 python Track Top1
Personal home page :python Classic exercises
- Exercises 1 : Output Dictionary key
- Title Description
- Question answer
- Exercise 2 : Output character string with odd position
- Title Description
- Question answer
- Conclusion
Here is a dictionary a, Such as a = {“honker”: 707, “hacker”: 707, “ker”: 707}, Output Dictionary a Of key, With ’,‘ Connect , Such as ‘honker’,‘hacker’,‘ker’. requirement key In ascending dictionary order
for example :a = {“honker”: 707, “hacker”: 707, “ker”: 707}, The output :honker,hacker,ker
Use... In the dictionary keys() Method take out all keys , And then use join Method splicing ,sort() Sort by sorting method
a = {
"honker": 707, "hacker": 707, "ker": 707}
keys = a.keys()
k_res = [k for k in keys]
print(','.join(str(k) for k in sorted(k_res)))
Here we need to pay attention to , If you take out the key directly, you will return a dict_keys Type data
Need to traverse the extraction key
a = {
"honker": 707, "hacker": 707, "ker": 707}
keys = a.keys()
print(keys)
The improvement code is as follows :
a = {
"honker": 707, "hacker": 707, "ker": 707}
keys = a.keys()
k_res = [k for k in keys]
print(','.join(str(k) for k in sorted(k_res)))
The operation results are as follows :
Give you a string a, Output a A string of characters with odd positions in ( The location number is from 1 Start ).
for example :a=‘honker’
The output :hne
Use the string slice index to get values ( The step size is set to 2 String that can take odd digits )
a = "honker"
print(a[::2])
The operation results are as follows :
Recommend a simulated interview 、 Brush question artifact website
Click the link to register
1、 Algorithm (398 topic ): Interview must brush 100 topic 、 Introduction to algorithm 、 Interview frequency list
2、SQL piece (82 topic ): Quick start 、SQL Will know 、SQL Advanced challenges 、 The real question of the interview
3、 The real question of the written test of Dachang : Bytes to beat 、 Meituan 、 Baidu 、 tencent …