Python has two functions .join() and os.path.join(), which do the following:
. join(): Concatenate string arrays. Concatenates the elements of a string, a tuple, and a list with the specified characters (separator) to generate a new string
os.path.join(): Combine multiple paths and return
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
>>#Operate on sequences (using ' ', ' - ' and ':' as separators respectively)
>> a=[ '1' , '2' , '3' , '4' , '5' ]
>> ' ' .join(a)
1 2 3 4 5
>> ';' .jion(a)
1-2-3-4-5
>> '.' .join(a)
1.2.3.4.5
>>#Operate on strings (using ' ', ' - ' and ':' as separators respectively)
>>b= 'hello world'
>> ' ' .join(b)
h e l l o w o r l d
>> '-' .join(b)
h-e-l-l-o- -w-o-r-l-d
>> ':' .jion(b)
h:e:l:l:o: :w:o:r:l:d
>>#Operate on tuples (using ' ', ' - ' and ':' as separators respectively)
>>c=( '1' , '2' , '3' , '4' , '5' )
>> ' ' .join(c)
1 2 3 4 5
>> '-' .join(c)
1-2-3-4-5
>> ':' .join(c)
1:2:3:4:5
>>#Unordered operation on dictionaries (using ' ', ' - ' and ':' as separators respectively)
>>d={ 'name1' : 'a' , 'name2' : 'b' , 'name3' : 'c' , 'name4' : 'd' }
>> ' ' .join(d)
name1 name2 name3 name4
>> '-' .join(d)
name1-name2-name3-name4
>> ':' .join(d)
name1:name2:name3:name4
>>#Performing operations on directories
>> import os
>>os.path.join( '/hello/' , 'good/date' , 'datbody' )
hello/good/ date /datbody
|
Related articles
Adding new content to a dictionary is done by adding new key/value pairs, modifying or deleting existing key/value pairs as in the following examples
clear() method is used to clear all the data in the dictionary, because it is an in-place operation, so it returns None (also can be interpreted as no return value)
Cookie, refers to the data (usually encrypted) that some websites store on the user's local terminal in order to identify the user and perform session tracking. For example, some websites require login to access a page, before login, you want to grab the
Each frame of the video is a picture, tracking an object in the video, decomposition down, in fact, is to find that object in each frame of the picture.
Learn to read and edit pixel values, use image ROI and other basic operations. The four main points are as follows: Accessing pixel values and modifying them Accessing image properties Set the region of interest (ROI) Splitting and merging images
I've been learning OpenCV recently, and I'll attach the code that I can run directly here, so hopefully it will help people learning OpenCV. Content: Introduction to OpenCV Installation of OpenCV Image opening/saving Video/camera opening, frame opera
I recently saw a Github project where the author wrote a script to automatically generate tiktok videos using Python, and it's getting a lot of buzz.
FastApi comes with interface documentation, which saves us a lot of work when developing back-end interfaces. It automatically identifies the parameters of the interface based on your code and also generates a description of the interface based on your
Usually you have developed a project using Flask first, and then developed several interfaces using FastAPI, but you can't move them all to FastAPI for a while, so you need to let the previous Flask application access the existing FastAPI application
python how to implement cache with expiration time, full text search, frequency limit In the previous article, I introduced you to using Python's own LRU cache to implement a cache with expiration time: One Day One Technique: Implementing an LRU Cache wi