Python Forum
How to call/read function for all elements in my list in python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to call/read function for all elements in my list in python
#1
Hello everybody,

i need help with a code i have written.

i have defined a function to compare two sequences with the def statement. Now i want to read the code of def function for all strings in my list, but i want to compare all strings.

it looks like that:

new_sequ=['XYZ','ZXY'...] example of list

def sequ(s1,s2):

..............
..............
sequ((new_sequ[0]),(new_sequ[1])) --> i call the function for the 0th and 1st of my list.

therefore i want to read the function for all strings in my list. I want to compare 0th with 1st.. 0th with 2nd ..0th with 3th.... and so on .... then 1st with 2nd....1st with 3rd element....and so on. 2nd with 3th ...2nd with 4th element.... like this.

I hope i described it good enough.
Reply
#2
look at itertools.product
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  unable to remove all elements from list based on a condition sg_python 3 373 Jan-27-2024, 04:03 PM
Last Post: deanhystad
  How to remove some elements from an array in python? gohanhango 9 981 Nov-28-2023, 08:35 AM
Last Post: Gribouillis
Question mypy unable to analyse types of tuple elements in a list comprehension tomciodev 1 427 Oct-17-2023, 09:46 AM
Last Post: tomciodev
  How to read module/class from list of strings? popular_dog 1 422 Oct-04-2023, 03:08 PM
Last Post: deanhystad
  for loops break when I call the list I'm looping through Radical 4 824 Sep-18-2023, 07:52 AM
Last Post: buran
  How do I call sys.argv list inside a function, from the CLI? billykid999 3 752 May-02-2023, 08:40 AM
Last Post: Gribouillis
  Checking if a string contains all or any elements of a list k1llcod3 1 1,023 Jan-29-2023, 04:34 AM
Last Post: deanhystad
  How to change the datatype of list elements? mHosseinDS86 9 1,899 Aug-24-2022, 05:26 PM
Last Post: deanhystad
  read a text file, find all integers, append to list oldtrafford 12 3,369 Aug-11-2022, 08:23 AM
Last Post: Pedroski55
  ValueError: Length mismatch: Expected axis has 8 elements, new values have 1 elements ilknurg 1 5,013 May-17-2022, 11:38 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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