Python Forum
Rearranging elements in Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rearranging elements in Python
#2
You should get an error because of line 2. The indentation is wrong.

with open("abc1.txt", "w+") as fw1, open("abc2.txt", "w+") as fw2:
    for element in p:
        if len(element.strip('Eth').split('/')[0]) == 1: # if you have one digit before the first /
            # write to abc1.txt
        else: # if you a sure that the input is correct else should work if you have three digits before /
            # write to abc2.txt
Or you can use regular expressions. I am not good at it. Never needed it so far :D
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Messages In This Thread
Rearranging elements in Python - by Nirmal - Nov-22-2018, 06:26 AM
RE: Rearranging elements in Python - by wavic - Nov-22-2018, 09:04 AM
RE: Rearranging elements in Python - by Nirmal - Nov-22-2018, 09:19 AM
RE: Rearranging elements in Python - by wavic - Nov-22-2018, 09:45 AM
RE: Rearranging elements in Python - by Nirmal - Nov-22-2018, 09:53 AM
RE: Rearranging elements in Python - by wavic - Nov-22-2018, 10:12 AM
RE: Rearranging elements in Python - by Nirmal - Nov-22-2018, 11:08 AM
RE: Rearranging elements in Python - by Gribouillis - Nov-22-2018, 12:29 PM
RE: Rearranging elements in Python - by Nirmal - Nov-23-2018, 03:28 AM
RE: Rearranging elements in Python - by Gribouillis - Nov-23-2018, 07:37 AM
RE: Rearranging elements in Python - by Nirmal - Nov-23-2018, 12:05 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to remove some elements from an array in python? gohanhango 9 1,439 Nov-28-2023, 08:35 AM
Last Post: Gribouillis
  ValueError: Length mismatch: Expected axis has 8 elements, new values have 1 elements ilknurg 1 5,315 May-17-2022, 11:38 AM
Last Post: Larz60+
  Sorting Elements via parameters pointing to those elements. rpalmer 3 2,676 Feb-10-2021, 04:53 PM
Last Post: rpalmer
  How does a set in python store the elements? idknuttin 5 2,881 Jul-10-2020, 10:46 PM
Last Post: Gribouillis
  How to sum up the elements of an integer using python split/join? mohanraj1986 5 3,619 Aug-27-2018, 09:13 AM
Last Post: perfringo
  Python show the combinations of list of elements zydjohn 6 7,577 Mar-06-2018, 11:23 PM
Last Post: zydjohn
  [split] Rearranging CSV columns and rows Ivan1 1 2,490 Aug-31-2017, 01:41 AM
Last Post: Ivan1

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020