Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
10583 มุมมอง

Hi Friends,

I have to swap set of characters.For example:

"6361" this  must be swapped as 6163.How we can achieve this?

 

 

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hello vadivel,

I agree with Stephen Ans. this is not odoo question this is related to python code. you can right python code to replace your later.

Here you Go! I have written sample method which will swap your latter in string. this will not only work for your number 3 and number 1.

I have written dynamic progrma which will ask for user Input which latter to be replace in string.

def swap_letter( a, b, dt):

    left_val_idx = []
    right_val_idx = []
    for d in dt:
        if d == a:
            left_val_idx.append(dt.index(d))
        elif d == b:
            right_val_idx.append(dt.index(b))

    swaped_word = ""

    for d in dt:

        if dt.index(d) in left_val_idx:
            swaped_word += b
        elif dt.index(d) in right_val_idx:
            swaped_word += a
        else:
            swaped_word += d

    return swaped_word

data = "686934543222133457768"

#Pass your two latter to be swap in string/word and your string as argument This will work for any case.

swap_data = swap_letter("8","9", data)

print "Swap DData ::",swap_data

Hope this will help.

Regards,

Anil.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi vadivel..

      There are some ways to swap characters.i give you some examples below:

 

1.           temp = "6361"
              print temp[2:]+ temp [:2]

2.           s="6361"
              swap_seq="0301"
              swapped=''.join([s[int(i)] for i in swap_seq])
              print swapped

 

Hope this will help you

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

These really are not Odoo questions, they are Python questions.  You should consider searching and posting these type of questions on stackoverflow.com.

There are a lot of smart programmers willing to help over there.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ก.ย. 17
6044
0
ธ.ค. 15
3464
1
พ.ย. 15
7290
1
เม.ย. 15
12014
0
มี.ค. 15
4172