Python Forum
Lists first item is a number however i cant compare it with an int getting syntax err
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Lists first item is a number however i cant compare it with an int getting syntax err
#1
Hello everyone,

when i try to compare list first element i am getting a syntax error. "if satırsayısı2=isimsatırlistesi[0]" this list is made of " isimsatırlistesi.append(int(satırsayısı))" so all the elements of the list are int not sure how to avoid this. Any suggestions ?


fhand=open("arb1.txt")

satırsayısı=0
isimsatırlistesi=list()
for line in fhand:
    satırsayısı=satırsayısı+1
    if line.startswith("Adres"):
        isimsatırlistesi.append(int(satırsayısı))

adressatırı=list()
satırsayısı2=0
satırdakikelimesayısı=0
for line in fhand:
        satırsayısı2=satırsayısı+1
        if satırsayısı2=isimsatırlistesi[0] # getting the error here
            print(line)
Reply


Messages In This Thread
Lists first item is a number however i cant compare it with an int getting syntax err - by Sutsro - Apr-22-2020, 08:45 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare two lists (with intersections). wnesbv 0 981 Jul-06-2022, 09:07 AM
Last Post: wnesbv
  Syntax when initializing empty lists Mark17 2 1,355 Jun-02-2022, 04:09 PM
Last Post: Mark17
  Remove an item from a list contained in another item in python CompleteNewb 19 5,669 Nov-11-2021, 06:43 AM
Last Post: Gribouillis
  Even number code syntax error MrCeez 1 2,269 May-02-2021, 06:43 PM
Last Post: Larz60+
  How do I add a number to every item in a list? john316 2 1,966 Oct-28-2020, 05:29 PM
Last Post: deanhystad
  Split dict of lists into smaller dicts of lists. pcs3rd 3 2,367 Sep-19-2020, 09:12 AM
Last Post: ibreeden
  Compare Two Lists and Replace Items In a List by Index nagymusic 2 2,876 May-10-2020, 05:28 AM
Last Post: deanhystad
  how to compare a list to a list of lists kevthew 1 1,794 Dec-22-2019, 11:43 AM
Last Post: ibreeden
  sort lists of lists with multiple criteria: similar values need to be treated equal stillsen 2 3,259 Mar-20-2019, 08:01 PM
Last Post: stillsen
  curious syntax with dictionary item inselbuch 3 2,749 Mar-09-2019, 04:21 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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